manage_dbserver
role is for managing the database cluster. It makes the
managing of the database cluster by giving key tasks. In all the roles, we have
used the tasks given in the this role.
Following are the dependencies and requirement of this role.
- Ansible
community.general
Ansible Module - Utilized when creating aditional users during a Postgres Install
This role allows users to pass following variables which helps managing day to day tasks:
Using this parameters user can set the database parameters.
Example:
pg_postgres_conf_params:
- name: listen_addresses
value: "*"
With this parameter, user can manage HBA (Host Based Authentication) entries.
pg_hba_ip_addresses:
- contype: "host"
users: "all"
databases: "all"
method: "scram-sha-256"
source: "127.0.0.1/32"
state: present
Replication slots management.
pg_slots:
- name: "physical_slot"
slot_type: "physical"
state: present
- name: "logical_slot"
slot_type: "logical"
output_plugin: "test_decoding"
state: present
database: "edb"
Postgres extensions management.
pg_extensions:
- name: "postgis"
database: "edb"
state: present
Grant privileges management.
pg_grant_privileges:
- roles: "efm_user"
database: "edb"
privileges: execute
schema: pg_catalog
objects: pg_current_wal_lsn(),pg_last_wal_replay_lsn(),pg_wal_replay_resume(),pg_wal_replay_pause()
type: function
Grant roles management.
pg_grant_roles:
- role: pg_monitor
user: enterprisedb
SQL script execution.
pg_sql_scripts:
- file_path: "/usr/edb/as12/share/edb-sample.sql"
db: edb
Copy file on remote host.
pg_copy_files:
- file: "./test.sh"
remote_file: "/var/lib/edb/test.sh"
owner: efm
group: efm
mode: 0700
Execute a query on a database.
pg_query:
- query: "Update test set a=b"
db: edb
.pgpass
file content management.
pg_pgpass_values:
- host: "127.0.0.1"
database: edb
user: enterprisedb
password: <password>
state: present
Databases management.
pg_databases:
- name: edb_gis
owner: edb
encoding: UTF-8
The manage_dbserver
role does depend on the following roles:
community.general
Content of the inventory.yml
file:
---
all:
children:
primary:
hosts:
primary1:
ansible_host: xxx.xxx.xxx.xxx
private_ip: xxx.xxx.xxx.xxx
standby:
hosts:
standby1:
ansible_host: xxx.xxx.xxx.xxx
private_ip: xxx.xxx.xxx.xxx
upstream_node_private_ip: xxx.xxx.xxx.xxx
replication_type: synchronous
standby2:
ansible_host: xxx.xxx.xxx.xxx
private_ip: xxx.xxx.xxx.xxx
upstream_node_private_ip: xxx.xxx.xxx.xxx
replication_type: asynchronous
Below is an example of how to include the manage_dbserver
role:
---
- hosts: primary,standby
name: Manage Postgres server
become: yes
gather_facts: yes
collections:
- edb_devops.edb_postgres
pre_tasks:
- name: Initialize the user defined variables
set_fact:
pg_version: 14
pg_type: "PG"
pg_postgres_conf_params:
- name: listen_addresses
value: "*"
pg_hba_ip_addresses:
- contype: "host"
users: "all"
databases: "all"
method: "scram-sha-256"
source: "127.0.0.1/32"
state: present
pg_slots:
- name: "physcial_slot"
slot_type: "physical"
state: present
- name: "logical_slot"
slot_type: "logical"
output_plugin: "test_decoding"
state: present
database: "edb"
roles:
- manage_dbserver
Defining and adding variables is done in the set_fact
of the pre_tasks
.
All the variables are available at:
- roles/manage_dbserver/defaults/main.yml
- roles/manage_dbserver/vars/EPAS_RedHat.yml
- roles/manage_dbserver/vars/PG_RedHat.yml
- roles/manage_dbserver/vars/EPAS_Debian.yml
- roles/manage_dbserver/vars/PG_Debian.yml
BSD
Author:
- Doug Ortiz
- Julien Tachoires
- Vibhor Kumar
- EDB Postgres
- DevOps
- [email protected] www.enterprisedb.com