added support to create users and dbs

This commit is contained in:
nd 2018-09-13 20:18:19 +02:00
parent c611a53558
commit 682cfa6259
No known key found for this signature in database
GPG key ID: 21B5CD4DEE3670E9
3 changed files with 30 additions and 3 deletions

View file

@ -1,2 +1,4 @@
postgresql: postgresql:
allowed_hosts: [] allowed_hosts: {}
dbs: {}
users: {}

View file

@ -1,6 +1,11 @@
- name: install postgres - name: install postgres
apt: apt:
pkg: postgresql pkg: "{{ item }}"
state: latest
update_cache: yes
with_items:
- postgresql
- python-psycopg2
- name: generate pg_hba - name: generate pg_hba
template: template:
@ -11,3 +16,18 @@
mode: 0640 mode: 0640
notify: notify:
- restart postgres - restart postgres
- name: add postgresql dbs
postgresql_db:
name: "{{ item.key }}"
become_user: postgres
become: true
with_dict: "{{ postgresql.dbs }}"
- name: add postgresql user(s)
postgresql_user:
name: "{{ item.key }}"
password: "{{ item.value }}"
become_user: postgres
become: true
with_dict: "{{ postgresql.users }}"

View file

@ -1,7 +1,12 @@
{% for item in postgresql.allowed_hosts %} {% for group in postgresql.allowed_hosts %}
# {{ group }}
{% for item in postgresql.allowed_hosts[group] %}
{{ item.type | default('host') }} {{ item.database | default('all') }} {{ item.user | default('all') }} {{ item.auth | default('md5') }} {{ item.type | default('host') }} {{ item.database | default('all') }} {{ item.user | default('all') }} {{ item.auth | default('md5') }}
{% endfor %} {% endfor %}
{% endfor %}
local all postgres peer local all postgres peer
local all all peer local all all peer
host all all 127.0.0.1/32 md5 host all all 127.0.0.1/32 md5