Last active
March 30, 2016 15:36
-
-
Save lesovsky/ba98e0f32a58dc44dfc9 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