2016-03-07 17:43:37 +01:00
|
|
|
---
|
|
|
|
- name: Install the packages needed by postgres when running behind a pgpool server
|
|
|
|
apt: pkg={{ item }} state={{ psql_pkg_state }}
|
|
|
|
with_items: '{{ postgresql_pgpool_pkgs }}'
|
|
|
|
when: psql_pgpool_install
|
|
|
|
notify: Restart postgresql
|
|
|
|
tags: [ 'postgresql', 'postgres', 'pgpool' ]
|
|
|
|
|
2016-06-07 18:26:14 +02:00
|
|
|
- name: Add the postgres user that will manage the recovery, if not postgres
|
2016-04-07 18:12:21 +02:00
|
|
|
become: True
|
|
|
|
become_user: postgres
|
|
|
|
postgresql_user: user={{ pgpool_recovery_user }} password={{ pgpool_recovery_user_pwd }} role_attr_flags=REPLICATION port={{ psql_db_port }}
|
|
|
|
when:
|
|
|
|
- ('{{ pgpool_recovery_user }}' != 'postgres')
|
|
|
|
- pgpool_recovery_user_pwd is defined
|
|
|
|
tags: [ 'postgresql', 'postgres', 'pgpool' ]
|
|
|
|
|
|
|
|
- name: Give access to the pgpool recovery user, if it is not postgres
|
|
|
|
lineinfile: name=/etc/postgresql/{{ psql_version }}/main/pg_hba.conf regexp="^host {{ item.0.name }} {{ pgpool_recovery_user }} {{ item.1 }}.*$" line="host {{ item.0.name }} {{ pgpool_recovery_user }} {{ item.1 }} md5"
|
|
|
|
with_subelements:
|
|
|
|
- '{{ psql_db_data | default([]) }}'
|
|
|
|
- allowed_hosts
|
|
|
|
when:
|
|
|
|
- psql_db_data is defined
|
|
|
|
- item.1 is defined
|
|
|
|
- pgpool_recovery_user_pwd is defined
|
|
|
|
notify: Reload postgresql
|
|
|
|
tags: [ 'postgresql', 'postgres', 'pgpool' ]
|
|
|
|
|
2016-06-07 18:26:14 +02:00
|
|
|
- name: Add the system user that will manage the recovery, if not postgres
|
|
|
|
user: user={{ pgpool_recovery_user }} password={{ pgpool_recovery_user_pwd | password_hash('sha512') }} groups=postgres shell=/bin/bash system=yes
|
|
|
|
when:
|
|
|
|
- ('{{ pgpool_recovery_user }}' != 'postgres')
|
|
|
|
- pgpool_recovery_user_pwd is defined
|
|
|
|
tags: [ 'postgresql', 'postgres', 'pgpool' ]
|
|
|
|
|
|
|
|
- name: Create the ssh keys for the recovery user
|
|
|
|
user: user={{ pgpool_recovery_user }} generate_ssh_key=yes ssh_key_bits=2048 ssh_key_file=.ssh/id_rsa ssh_key_type=rsa
|
|
|
|
tags: [ 'postgresql', 'postgres', 'pgpool' ]
|
|
|
|
|
2016-04-07 18:12:21 +02:00
|
|
|
- name: Install the pgpool recovery and remote restart scripts. They assume that the postgresql hosts can talk to each other
|
|
|
|
template: src={{ item.1 }}.j2 dest={{ item.0.backend_data_directory }}/{{ item.1 }} owner=postgres group=postgres mode=0500
|
|
|
|
with_nested:
|
|
|
|
- '{{ pgpool_backends | default([]) }}'
|
|
|
|
- [ '{{ pgpool_recovery_stage1_script }}', '{{ pgpool_recovery_stage2_script }}', '{{ pgpool_remote_start_script }}' ]
|
|
|
|
tags: [ 'postgresql', 'postgres', 'pgpool' ]
|
|
|
|
|
2016-06-07 18:26:14 +02:00
|
|
|
- name: Set the postgresql configuration parameters needed by pgpool
|
|
|
|
action: configfile path=/etc/postgresql/{{ psql_version }}/main/postgresql.conf key={{ item.name }} value="{{ item.value }}"
|
|
|
|
with_items: '{{ psql_wal_files_conf }}'
|
|
|
|
when:
|
|
|
|
- item.set
|
|
|
|
- psql_wal_files_archiving_enabled
|
|
|
|
notify: Restart postgresql with pgpool config
|
|
|
|
tags: [ 'postgresql', 'postgres', 'pg_conf', 'pgpool' ]
|
|
|
|
|
|
|
|
- name: Install the sudoers config that permits the postgres user to restart the service after a recovery
|
|
|
|
template: src=postgresql-sudoers.j2 dest=/etc/sudoers.d/postgres-pgpool owner=root group=root mode=0440
|
|
|
|
tags: [ 'postgres', 'postgresql', 'sudo', 'pgpool' ]
|
|
|
|
|
|
|
|
- name: Install a script that cleans up the wal log archives
|
|
|
|
template: src=postgresql_wal_backup_and_removal.j2 dest=/usr/local/sbin/postgresql_wal_backup_and_removal owner=root group=root mode=0755
|
|
|
|
tags: [ 'postgresql', 'postgres', 'pgpool' ]
|
|
|
|
|
|
|
|
- name: Install a cron job to cleanup the wal log archives
|
|
|
|
cron: name="Clean up the postgresql WAL log archives" user=postgres job="/usr/local/sbin/postgresql_wal_backup_and_removal > {{ psql_log_dir }}/wal_removal.log 2>&1" special_time=daily
|
|
|
|
tags: [ 'postgresql', 'postgres', 'pgpool' ]
|