|
1 | 1 | # PgBouncer |
2 | 2 | - name: PgBouncer - download & install dependencies |
3 | | - apt: |
| 3 | + ansible.builtin.apt: |
4 | 4 | pkg: |
5 | 5 | - build-essential |
6 | | - - libssl-dev |
7 | | - - pkg-config |
8 | 6 | - libevent-dev |
| 7 | + - libssl-dev |
9 | 8 | - libsystemd-dev |
10 | | - update_cache: yes |
| 9 | + - pkg-config |
| 10 | + update_cache: true |
11 | 11 | cache_valid_time: 3600 |
12 | 12 |
|
13 | 13 | - name: PgBouncer - download latest release |
14 | | - get_url: |
15 | | - url: "https://www.pgbouncer.org/downloads/files/{{ pgbouncer_release }}/pgbouncer-{{ pgbouncer_release }}.tar.gz" |
16 | | - dest: /tmp/pgbouncer-{{ pgbouncer_release }}.tar.gz |
| 14 | + ansible.builtin.get_url: |
17 | 15 | checksum: "{{ pgbouncer_release_checksum }}" |
| 16 | + dest: "/tmp/pgbouncer-{{ pgbouncer_release }}.tar.gz" |
18 | 17 | timeout: 60 |
| 18 | + url: "https://www.pgbouncer.org/downloads/files/{{ pgbouncer_release }}/pgbouncer-{{ pgbouncer_release }}.tar.gz" |
19 | 19 |
|
20 | 20 | - name: PgBouncer - unpack archive |
21 | | - unarchive: |
22 | | - remote_src: yes |
23 | | - src: /tmp/pgbouncer-{{ pgbouncer_release }}.tar.gz |
24 | | - dest: /tmp |
25 | | - become: yes |
| 21 | + ansible.builtin.unarchive: |
| 22 | + dest: '/tmp' |
| 23 | + remote_src: true |
| 24 | + src: "/tmp/pgbouncer-{{ pgbouncer_release }}.tar.gz" |
| 25 | + become: true |
26 | 26 |
|
27 | 27 | - name: PgBouncer - configure |
28 | | - shell: |
29 | | - cmd: "./configure --prefix=/usr/local --with-systemd" |
30 | | - chdir: /tmp/pgbouncer-{{ pgbouncer_release }} |
31 | | - become: yes |
32 | | - |
33 | | -- name: PgBouncer - build |
34 | | - make: |
35 | | - chdir: /tmp/pgbouncer-{{ pgbouncer_release }} |
36 | | - become: yes |
37 | | - |
38 | | -- name: PgBouncer - install |
39 | | - make: |
40 | | - chdir: /tmp/pgbouncer-{{ pgbouncer_release }} |
41 | | - target: install |
42 | | - become: yes |
| 28 | + ansible.builtin.command: |
| 29 | + cmd: './configure --prefix=/usr/local --with-systemd' |
| 30 | + args: |
| 31 | + chdir: "/tmp/pgbouncer-{{ pgbouncer_release }}" |
| 32 | + become: true |
| 33 | + |
| 34 | +- name: PgBouncer - build and install |
| 35 | + community.general.make: |
| 36 | + chdir: "/tmp/pgbouncer-{{ pgbouncer_release }}" |
| 37 | + target: "{{ pgbouncer_make_item }}" |
| 38 | + become: true |
| 39 | + loop: |
| 40 | + - 'all' |
| 41 | + - 'install' |
| 42 | + loop_control: |
| 43 | + loop_var: 'pgbouncer_make_item' |
43 | 44 |
|
44 | 45 | - name: Create pgbouncer user |
45 | | - user: |
46 | | - name: pgbouncer |
47 | | - shell: /bin/false |
48 | | - comment: PgBouncer user |
49 | | - groups: postgres,ssl-cert |
50 | | - |
51 | | -- name: PgBouncer - create a directory if it does not exist |
52 | | - file: |
53 | | - path: /etc/pgbouncer |
54 | | - state: directory |
55 | | - owner: pgbouncer |
56 | | - group: pgbouncer |
57 | | - mode: '0700' |
58 | | - |
59 | | -- name: PgBouncer - create a directory if it does not exist |
60 | | - file: |
61 | | - state: directory |
62 | | - owner: pgbouncer |
63 | | - group: pgbouncer |
64 | | - path: '{{ item }}' |
65 | | - mode: '0775' |
| 46 | + ansible.builtin.user: |
| 47 | + comment: 'PgBouncer user' |
| 48 | + groups: 'postgres,ssl-cert' |
| 49 | + name: 'pgbouncer' |
| 50 | + shell: '/usr/sbin/nolign' |
| 51 | + state: 'present' |
| 52 | + |
| 53 | +- name: Create PgBouncer directories if they do not exist |
| 54 | + ansible.builtin.file: |
| 55 | + group: 'pgbouncer' |
| 56 | + mode: "{{ pgbouncer_dir_item['mode'] }}" |
| 57 | + owner: 'pgbouncer' |
| 58 | + path: "{{ pgbouncer_dir_item['dir'] }}" |
| 59 | + state: 'directory' |
| 60 | + loop_control: |
| 61 | + loop_var: 'pgbouncer_dir_item' |
66 | 62 | with_items: |
67 | | - - '/etc/pgbouncer-custom' |
68 | | - |
69 | | -- name: create placeholder config files |
70 | | - file: |
71 | | - path: '/etc/pgbouncer-custom/{{ item }}' |
72 | | - state: touch |
73 | | - owner: pgbouncer |
74 | | - group: pgbouncer |
75 | | - mode: 0664 |
| 63 | + - { mode: '0700', dir: '/etc/pgbouncer' } |
| 64 | + - { mode: '0775', dir: '/etc/pgbouncer-custom' } |
| 65 | + |
| 66 | +- name: create PgBouncer placeholder config files |
| 67 | + ansible.builtin.file: |
| 68 | + group: 'pgbouncer' |
| 69 | + mode: '0664' |
| 70 | + owner: 'pgbouncer' |
| 71 | + path: "/etc/pgbouncer-custom/{{ pgbouncer_config_item }}" |
| 72 | + state: 'touch' |
| 73 | + loop_control: |
| 74 | + loop_var: 'pgbouncer_config_item' |
76 | 75 | with_items: |
77 | | - - 'generated-optimizations.ini' |
78 | 76 | - 'custom-overrides.ini' |
| 77 | + - 'generated-optimizations.ini' |
79 | 78 | - 'ssl-config.ini' |
80 | 79 |
|
81 | 80 | - name: PgBouncer - adjust pgbouncer.ini |
82 | | - copy: |
83 | | - src: files/pgbouncer_config/pgbouncer.ini.j2 |
84 | | - dest: /etc/pgbouncer/pgbouncer.ini |
85 | | - owner: pgbouncer |
| 81 | + ansible.builtin.copy: |
| 82 | + dest: '/etc/pgbouncer/pgbouncer.ini' |
86 | 83 | mode: '0700' |
| 84 | + owner: 'pgbouncer' |
| 85 | + src: 'files/pgbouncer_config/pgbouncer.ini.j2' |
87 | 86 |
|
88 | | -- name: PgBouncer - create a directory if it does not exist |
89 | | - file: |
90 | | - path: /etc/pgbouncer/userlist.txt |
91 | | - state: touch |
92 | | - owner: pgbouncer |
| 87 | +- name: PgBouncer - create a userlist file if it does not exist |
| 88 | + ansible.builtin.file: |
93 | 89 | mode: '0700' |
| 90 | + owner: 'pgbouncer' |
| 91 | + path: '/etc/pgbouncer/userlist.txt' |
| 92 | + state: 'touch' |
94 | 93 |
|
95 | 94 | - name: import /etc/tmpfiles.d/pgbouncer.conf |
96 | | - template: |
97 | | - src: files/pgbouncer_config/tmpfiles.d-pgbouncer.conf.j2 |
98 | | - dest: /etc/tmpfiles.d/pgbouncer.conf |
99 | | - become: yes |
| 95 | + ansible.builtin.template: |
| 96 | + dest: '/etc/tmpfiles.d/pgbouncer.conf' |
| 97 | + src: 'files/pgbouncer_config/tmpfiles.d-pgbouncer.conf.j2' |
| 98 | + become: true |
100 | 99 |
|
101 | 100 | - name: PgBouncer - By default allow ssl connections. |
102 | | - become: yes |
103 | | - copy: |
104 | | - dest: /etc/pgbouncer-custom/ssl-config.ini |
105 | | - content: | |
106 | | - client_tls_sslmode = allow |
| 101 | + ansible.builtin.lineinfile: |
| 102 | + line: 'client_tls_sslmode = allow' |
| 103 | + path: '/etc/pgbouncer-custom/ssl-config.ini' |
| 104 | + become: true |
107 | 105 |
|
108 | 106 | - name: Grant pg_hba and pgbouncer grp perm for adminapi updates |
109 | | - shell: | |
110 | | - chmod g+w /etc/postgresql/pg_hba.conf |
111 | | - chmod g+w /etc/pgbouncer-custom/ssl-config.ini |
| 107 | + ansible.builtin.file: |
| 108 | + mode: '0664' |
| 109 | + path: "{{ pgbouncer_group_item }}" |
| 110 | + loop: |
| 111 | + - /etc/pgbouncer-custom/ssl-config.ini |
| 112 | + - /etc/postgresql/pg_hba.conf |
| 113 | + loop_control: |
| 114 | + loop_var: 'pgbouncer_group_item' |
112 | 115 |
|
113 | 116 | # Add fail2ban filter |
114 | 117 | - name: import jail.d/pgbouncer.conf |
115 | | - template: |
116 | | - src: files/fail2ban_config/jail-pgbouncer.conf.j2 |
117 | | - dest: /etc/fail2ban/jail.d/pgbouncer.conf |
118 | | - become: yes |
| 118 | + ansible.builtin.template: |
| 119 | + dest: '/etc/fail2ban/jail.d/pgbouncer.conf' |
| 120 | + src: 'files/fail2ban_config/jail-pgbouncer.conf.j2' |
| 121 | + become: true |
119 | 122 |
|
120 | 123 | - name: import filter.d/pgbouncer.conf |
121 | | - template: |
122 | | - src: files/fail2ban_config/filter-pgbouncer.conf.j2 |
123 | | - dest: /etc/fail2ban/filter.d/pgbouncer.conf |
124 | | - become: yes |
| 124 | + ansible.builtin.template: |
| 125 | + dest: '/etc/fail2ban/filter.d/pgbouncer.conf' |
| 126 | + src: 'files/fail2ban_config/filter-pgbouncer.conf.j2' |
| 127 | + become: true |
125 | 128 |
|
126 | 129 | # Add systemd file for PgBouncer |
127 | | -- name: PgBouncer - import postgresql.service |
128 | | - template: |
129 | | - src: files/pgbouncer_config/pgbouncer.service.j2 |
130 | | - dest: /etc/systemd/system/pgbouncer.service |
131 | | - become: yes |
| 130 | +- name: PgBouncer - import pgbouncer.service |
| 131 | + ansible.builtin.template: |
| 132 | + dest: '/etc/systemd/system/pgbouncer.service' |
| 133 | + src: 'files/pgbouncer_config/pgbouncer.service.j2' |
| 134 | + become: true |
132 | 135 |
|
133 | 136 | - name: PgBouncer - reload systemd |
134 | | - systemd: |
135 | | - daemon_reload: yes |
| 137 | + ansible.builtin.systemd_service: |
| 138 | + daemon_reload: true |
0 commit comments