Skip to content

Commit a720562

Browse files
authored
refactor(ansible): bring our ansible up to modern ansible-lint standards (#1833)
1 parent 8b687e3 commit a720562

File tree

1 file changed

+97
-94
lines changed

1 file changed

+97
-94
lines changed

ansible/tasks/setup-pgbouncer.yml

Lines changed: 97 additions & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -1,135 +1,138 @@
11
# PgBouncer
22
- name: PgBouncer - download & install dependencies
3-
apt:
3+
ansible.builtin.apt:
44
pkg:
55
- build-essential
6-
- libssl-dev
7-
- pkg-config
86
- libevent-dev
7+
- libssl-dev
98
- libsystemd-dev
10-
update_cache: yes
9+
- pkg-config
10+
update_cache: true
1111
cache_valid_time: 3600
1212

1313
- 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:
1715
checksum: "{{ pgbouncer_release_checksum }}"
16+
dest: "/tmp/pgbouncer-{{ pgbouncer_release }}.tar.gz"
1817
timeout: 60
18+
url: "https://www.pgbouncer.org/downloads/files/{{ pgbouncer_release }}/pgbouncer-{{ pgbouncer_release }}.tar.gz"
1919

2020
- 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
2626

2727
- 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'
4344

4445
- 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'
6662
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'
7675
with_items:
77-
- 'generated-optimizations.ini'
7876
- 'custom-overrides.ini'
77+
- 'generated-optimizations.ini'
7978
- 'ssl-config.ini'
8079

8180
- 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'
8683
mode: '0700'
84+
owner: 'pgbouncer'
85+
src: 'files/pgbouncer_config/pgbouncer.ini.j2'
8786

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:
9389
mode: '0700'
90+
owner: 'pgbouncer'
91+
path: '/etc/pgbouncer/userlist.txt'
92+
state: 'touch'
9493

9594
- 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
10099

101100
- 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
107105

108106
- 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'
112115

113116
# Add fail2ban filter
114117
- 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
119122

120123
- 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
125128

126129
# 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
132135

133136
- name: PgBouncer - reload systemd
134-
systemd:
135-
daemon_reload: yes
137+
ansible.builtin.systemd_service:
138+
daemon_reload: true

0 commit comments

Comments
 (0)