Skip to content

Instantly share code, notes, and snippets.

@lesovsky
Last active March 30, 2016 15:36
Show Gist options
  • Save lesovsky/ba98e0f32a58dc44dfc9 to your computer and use it in GitHub Desktop.
Save lesovsky/ba98e0f32a58dc44dfc9 to your computer and use it in GitHub Desktop.
pgbouncer-create-userlist.yml
---
- 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