xoxys.postgres/tasks/config.yml

49 lines
1.7 KiB
YAML
Raw Normal View History

2018-10-16 18:53:36 +00:00
---
- block:
- name: Setup global config file
template:
src: postgresql/data/postgresql.conf.j2
dest: "{{ __postgres_config_path }}/postgresql.conf"
mode: 0600
notify: __postgres_restart
2018-10-22 20:10:06 +00:00
- name: Create local users for pam auth
user:
name: "{{ item.name }}"
2018-10-22 21:33:14 +00:00
password: "{{ item.password | password_hash('sha512', 65534 | random(seed=inventory_hostname) | string) }}"
2018-10-22 20:35:27 +00:00
state: "{{ item.state | default('present') }}"
2018-10-22 20:10:06 +00:00
with_items: "{{ postgres_users }}"
2018-10-22 21:05:52 +00:00
no_log: True
2018-10-22 20:10:06 +00:00
when: item.pam_user | default(False)
- name: Setup client authentication
template:
src: postgresql/data/pg_hba.conf.j2
dest: "{{ __postgres_config_path }}/pg_hba.conf"
mode: 0600
notify: __postgres_restart
2018-10-16 18:53:36 +00:00
become: True
become_user: root
2018-10-18 20:59:39 +00:00
2018-10-18 21:13:48 +00:00
- name: Force all notified handlers to activate pg_hba.conf
meta: flush_handlers
2018-10-18 20:59:39 +00:00
- name: Ensure PostgreSQL users are present
2018-10-18 21:09:06 +00:00
postgresql_user:
2018-10-18 20:59:39 +00:00
name: "{{ item.name }}"
2018-10-23 20:59:45 +00:00
password: "{{ item.password + item.name | hash('md5') }}"
2018-10-18 20:59:39 +00:00
encrypted: "{{ item.encrypted | default('yes') }}"
priv: "{{ item.priv | default(omit) }}"
role_attr_flags: "{{ item.role_attr_flags | default(omit) }}"
db: "{{ item.db | default(omit) }}"
login_host: "{{ item.login_host | default('localhost') }}"
login_password: "{{ item.login_password | default(omit) }}"
2018-10-18 21:07:39 +00:00
login_user: "{{ item.login_user | default(postgres_user) }}"
login_unix_socket: "{{ item.login_unix_socket | default(postgres_socket_directories[0]) }}"
2018-10-18 20:59:39 +00:00
port: "{{ item.port | default(omit) }}"
state: "{{ item.state | default('present') }}"
2018-10-22 21:05:52 +00:00
no_log: True
2018-10-18 21:07:39 +00:00
with_items: "{{ postgres_users }}"
2018-10-18 20:59:39 +00:00
become: true
2018-10-18 21:07:39 +00:00
become_user: "{{ postgres_user }}"