mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-07-28 07:31:23 -07:00
Initial commit
This commit is contained in:
commit
aebc1b03fd
4861 changed files with 812621 additions and 0 deletions
|
@ -0,0 +1,30 @@
|
|||
# General:
|
||||
pg_user: postgres
|
||||
db_default: postgres
|
||||
|
||||
pg_package_list:
|
||||
- apt-utils
|
||||
- postgresql
|
||||
- postgresql-contrib
|
||||
- python3-psycopg2
|
||||
|
||||
packages_to_remove:
|
||||
- postgresql
|
||||
- postgresql-contrib
|
||||
- postgresql-server
|
||||
- postgresql-libs
|
||||
- python3-psycopg2
|
||||
|
||||
# Master specific defaults:
|
||||
master_root_dir: '/var/lib/pgsql/master'
|
||||
master_data_dir: '{{ master_root_dir }}/data'
|
||||
master_postgresql_conf: '{{ master_data_dir }}/postgresql.conf'
|
||||
master_pg_hba_conf: '{{ master_data_dir }}/pg_hba.conf'
|
||||
master_port: 5433
|
||||
|
||||
# Replica specific defaults:
|
||||
replica_root_dir: '/var/lib/pgsql/replica'
|
||||
replica_data_dir: '{{ replica_root_dir }}/data'
|
||||
replica_postgresql_conf: '{{ replica_data_dir }}/postgresql.conf'
|
||||
replica_pg_hba_conf: '{{ replica_data_dir }}/pg_hba.conf'
|
||||
replica_port: 5434
|
|
@ -0,0 +1,23 @@
|
|||
- name: Stop services
|
||||
become: yes
|
||||
become_user: '{{ pg_user }}'
|
||||
shell: '{{ pg_ctl }} -D {{ item.datadir }} -o "-p {{ item.port }}" -m immediate stop'
|
||||
loop:
|
||||
- { datadir: '{{ master_data_dir }}', port: '{{ master_port }}' }
|
||||
- { datadir: '{{ replica_data_dir }}', port: '{{ replica_port }}' }
|
||||
listen: stop postgresql
|
||||
|
||||
- name: Remove packages
|
||||
apt:
|
||||
name: '{{ packages_to_remove }}'
|
||||
state: absent
|
||||
listen: cleanup postgresql
|
||||
|
||||
- name: Remove FS objects
|
||||
file:
|
||||
state: absent
|
||||
path: "{{ item }}"
|
||||
loop:
|
||||
- "{{ master_root_dir }}"
|
||||
- "{{ replica_root_dir }}"
|
||||
listen: cleanup postgresql
|
|
@ -0,0 +1,8 @@
|
|||
# Copyright: (c) 2019, Andrew Klychkov (@Andersson007) <aaklychkov@mail.ru>
|
||||
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
|
||||
# Setup PostgreSQL master-standby replication into one container:
|
||||
- import_tasks: setup_postgresql_cluster.yml
|
||||
when:
|
||||
- ansible_distribution == 'Ubuntu'
|
||||
- ansible_distribution_major_version >= '18'
|
|
@ -0,0 +1,84 @@
|
|||
- name: Install packages
|
||||
apt:
|
||||
name: '{{ pg_package_list }}'
|
||||
notify: cleanup postgresql
|
||||
- name: Create root dirs
|
||||
file:
|
||||
state: directory
|
||||
path: '{{ item }}'
|
||||
owner: postgres
|
||||
group: postgres
|
||||
mode: '0700'
|
||||
loop:
|
||||
- '{{ master_root_dir }}'
|
||||
- '{{ master_data_dir }}'
|
||||
- '{{ replica_root_dir }}'
|
||||
- '{{ replica_data_dir }}'
|
||||
notify: cleanup postgresql
|
||||
- name: Find initdb
|
||||
shell: find /usr/lib -type f -name "initdb"
|
||||
register: result
|
||||
- name: Set path to initdb
|
||||
set_fact:
|
||||
initdb: '{{ result.stdout }}'
|
||||
- name: Initialize databases
|
||||
become: true
|
||||
become_user: '{{ pg_user }}'
|
||||
shell: '{{ initdb }} --pgdata {{ item }}'
|
||||
loop:
|
||||
- '{{ master_data_dir }}'
|
||||
- '{{ replica_data_dir }}'
|
||||
- name: Copy config templates
|
||||
template:
|
||||
src: '{{ item.conf_templ }}'
|
||||
dest: '{{ item.conf_dest }}'
|
||||
owner: postgres
|
||||
group: postgres
|
||||
force: true
|
||||
loop:
|
||||
- conf_templ: master_postgresql.conf.j2
|
||||
conf_dest: '{{ master_postgresql_conf }}'
|
||||
- conf_templ: replica_postgresql.conf.j2
|
||||
conf_dest: '{{ replica_postgresql_conf }}'
|
||||
- conf_templ: pg_hba.conf.j2
|
||||
conf_dest: '{{ master_pg_hba_conf }}'
|
||||
- conf_templ: pg_hba.conf.j2
|
||||
conf_dest: '{{ replica_pg_hba_conf }}'
|
||||
- name: Find pg_ctl
|
||||
shell: find /usr/lib -type f -name "pg_ctl"
|
||||
register: result
|
||||
- name: Set path to initdb
|
||||
set_fact:
|
||||
pg_ctl: '{{ result.stdout }}'
|
||||
- name: Start servers
|
||||
become: true
|
||||
become_user: '{{ pg_user }}'
|
||||
shell: '{{ pg_ctl }} -D {{ item.datadir }} -o "-p {{ item.port }}" start'
|
||||
loop:
|
||||
- datadir: '{{ master_data_dir }}'
|
||||
port: '{{ master_port }}'
|
||||
- datadir: '{{ replica_data_dir }}'
|
||||
port: '{{ replica_port }}'
|
||||
notify: stop postgresql
|
||||
- name: Check connectivity to the master and get PostgreSQL version
|
||||
become: true
|
||||
become_user: '{{ pg_user }}'
|
||||
postgresql_ping:
|
||||
db: '{{ db_default }}'
|
||||
login_user: '{{ pg_user }}'
|
||||
login_port: '{{ master_port }}'
|
||||
register: result
|
||||
- name: Check connectivity to the replica and get PostgreSQL version
|
||||
become: true
|
||||
become_user: '{{ pg_user }}'
|
||||
postgresql_ping:
|
||||
db: '{{ db_default }}'
|
||||
login_user: '{{ pg_user }}'
|
||||
login_port: '{{ replica_port }}'
|
||||
- name: Define server version
|
||||
set_fact:
|
||||
pg_major_version: '{{ result.server_version.major }}'
|
||||
pg_minor_version: '{{ result.server_version.minor }}'
|
||||
- name: Print PostgreSQL version
|
||||
debug:
|
||||
msg: PostgreSQL version is {{ pg_major_version }}.{{ pg_minor_version }}
|
|
@ -0,0 +1,28 @@
|
|||
# Important parameters:
|
||||
listen_addresses='*'
|
||||
port = {{ master_port }}
|
||||
wal_level = logical
|
||||
max_wal_senders = 8
|
||||
track_commit_timestamp = on
|
||||
max_replication_slots = 10
|
||||
|
||||
# Unimportant parameters:
|
||||
max_connections=10
|
||||
shared_buffers=8MB
|
||||
dynamic_shared_memory_type=posix
|
||||
log_destination='stderr'
|
||||
logging_collector=on
|
||||
log_directory='log'
|
||||
log_filename='postgresql-%a.log'
|
||||
log_truncate_on_rotation=on
|
||||
log_rotation_age=1d
|
||||
log_rotation_size=0
|
||||
log_line_prefix='%m[%p]'
|
||||
log_timezone='W-SU'
|
||||
datestyle='iso,mdy'
|
||||
timezone='W-SU'
|
||||
lc_messages='en_US.UTF-8'
|
||||
lc_monetary='en_US.UTF-8'
|
||||
lc_numeric='en_US.UTF-8'
|
||||
lc_time='en_US.UTF-8'
|
||||
default_text_search_config='pg_catalog.english'
|
|
@ -0,0 +1,7 @@
|
|||
local all all trust
|
||||
local replication logical_replication trust
|
||||
host replication logical_replication 127.0.0.1/32 trust
|
||||
host replication logical_replication 0.0.0.0/0 trust
|
||||
local all logical_replication trust
|
||||
host all logical_replication 127.0.0.1/32 trust
|
||||
host all logical_replication 0.0.0.0/0 trust
|
|
@ -0,0 +1,28 @@
|
|||
# Important parameters:
|
||||
listen_addresses='*'
|
||||
port = {{ replica_port }}
|
||||
wal_level = logical
|
||||
max_wal_senders = 8
|
||||
track_commit_timestamp = on
|
||||
max_replication_slots = 10
|
||||
|
||||
# Unimportant parameters:
|
||||
max_connections=10
|
||||
shared_buffers=8MB
|
||||
dynamic_shared_memory_type=posix
|
||||
log_destination='stderr'
|
||||
logging_collector=on
|
||||
log_directory='log'
|
||||
log_filename='postgresql-%a.log'
|
||||
log_truncate_on_rotation=on
|
||||
log_rotation_age=1d
|
||||
log_rotation_size=0
|
||||
log_line_prefix='%m[%p]'
|
||||
log_timezone='W-SU'
|
||||
datestyle='iso,mdy'
|
||||
timezone='W-SU'
|
||||
lc_messages='en_US.UTF-8'
|
||||
lc_monetary='en_US.UTF-8'
|
||||
lc_numeric='en_US.UTF-8'
|
||||
lc_time='en_US.UTF-8'
|
||||
default_text_search_config='pg_catalog.english'
|
Loading…
Add table
Add a link
Reference in a new issue