-
-
Save nordicdyno/a5afc27f6078ec3b2202a1da3692a1f2 to your computer and use it in GitHub Desktop.
pgbouncer-create-userlist.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
- hosts: all | |
vars: | |
userlist_file: /etc/pgbouncer/userlist.txt | |
userlist_owner: postgres | |
remote_user: root | |
tasks: | |
- name: "Stage 1: create temporary userlist.txt" | |
sudo: yes | |
sudo_user: postgres | |
shell: psql -AtXF' ' -c "select rolname,rolpassword from pg_authid" |sed -e 's/^/\"/' -e 's/$/\"/' -e 's/ /\" \"/' > /tmp/userlist.txt | |
- stat: path=/tmp/userlist.txt | |
register: st | |
- name: "Stage 2: Stop if temporary userlist.txt is empty" | |
fail: msg="Temporary userlist.txt is empty. Probably psql can't connect to postgres." | |
when: st.stat.size == 0 | |
- name: "Stage 3: replace existing userlist.txt" | |
command: mv /tmp/userlist.txt {{ userlist_file }} | |
when: st.stat.size > 0 | |
- name: "Stage 4: set permission on userlist.txt" | |
file: | |
state: file | |
dest: "{{ userlist_file }}" | |
owner: "{{ userlist_owner }}" | |
mode: 0600 | |
ignore_errors: yes |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment