Skip to content

Commit

Permalink
Revert "Adding optimized codes"
Browse files Browse the repository at this point in the history
This reverts commit 33b396f.
  • Loading branch information
vibhorkumar123 committed Oct 11, 2020
1 parent 33b396f commit e789e9d
Show file tree
Hide file tree
Showing 177 changed files with 4,368 additions and 3,178 deletions.
53 changes: 37 additions & 16 deletions playbook.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,41 @@
pre_tasks:
- name: Initialize the user defined variables
set_fact:
os: "CentOS7"
pg_version: 12
pg_type: "PG"
pg_data: "/data/pgdata"
pg_wal: "/data/pg_wal"
yum_username: ""
yum_password: ""
standby_quorum_types: "ANY" # Quorum type can be ANY or FIRST
OS: "CentOS7"
PG_VERSION: "12"
PG_TYPE: "PG"
PG_DATA: "/data/pgdata"
PG_WAL: "/data/pg_wal"
EDB_YUM_USERNAME: ""
EDB_YUM_PASSWORD: ""
STANDBY_QUORUM_TYPE: "ANY" # Quorum type can be ANY or FIRST

roles:
- setup_repo
- install_dbserver
- init_dbserver
- setup_replication
- setup_efm
- setup_pem
- manage_dbserver
tasks:
- name: Iterate through repo role with items from hosts file
include_role:
name: process_vars
with_dict: "{{ servers }}"
- name: Iterate through repo role with items from hosts file
include_role:
name: setup_repo
with_dict: "{{ servers }}"
- name: Iterate through install role with items from hosts file
include_role:
name: install_dbserver
with_dict: "{{ servers }}"
- name: Iterate through initialize role with items from hosts file
include_role:
name: init_dbserver
with_dict: "{{ servers }}"
- name: Iterate through replication role with items from hosts file
include_role:
name: setup_replication
with_dict: "{{ servers }}"
- name: Iterate through efm install role with items from hosts file
include_role:
name: setup_efm
with_dict: "{{ servers }}"
- name: Iterate through pem install role with items from hosts file
include_role:
name: setup_pem
with_dict: "{{ servers }}"
58 changes: 33 additions & 25 deletions roles/init_dbserver/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ Role Variables

When executing the role via ansible there are two required variables:

* os
* OS
Operating Systems supported are: CentOS7 and RHEL7
* pg_version
* PG_VERSION
Postgres Versions supported are: 10, 11 and 12
* pg_type
* PG_TYPE
Database Engine supported are: PG and EPAS

These and other variables can be assigned in the 'pre_tasks' definition of the section: 'How to include the 'init_dbserver' role in your Playbook'
Expand Down Expand Up @@ -94,20 +94,28 @@ Below is an example of how to include the init_dbserver role:
# Define or re-define any variables previously assigned
- name: Initialize the user defined variables
set_fact:
os: "CentOS7"
pg_type: "EPAS"
pg_version: 12
efm_version: 4.0
pg_data: "/data/pgdata"
OS: "OS"
PG_TYPE: "PG_TYPE"
PG_VERSION: "PG_VERSION"
EFM_VERSION: "EFM_VERSION"
PG_DATA: "/data/pgdata"

tasks:
- name: Iterate through role with items from hosts file
include_role:
name: process_vars
with_dict: "{{ servers }}"
- name: Iterate through role with items from hosts file
include_role:
name: init_dbserver
with_dict: "{{ servers }}"

roles:
- init_dbserver

**Defining and adding variables can be done in the set_fact of the pre-tasks.**

All the variables are available at:
- [roles/init_dbserver/vars/EPAS.yml](./vars/EPAS.yml)
- [roles/init_dbserver/vars/PG.yml](./vars/PG.yml)
- [roles/init_dbserver/vars/edb-pg.yml](./vars/edb-pg.yml)
- [roles/init_dbserver/vars/edb-epas.yml](./vars/edb-epas.yml)

Database Engines Supported
----------------
Expand Down Expand Up @@ -140,35 +148,35 @@ CentOS 7: Community Postgresql with command line parameters
----------------


ansible-playbook playbook.yml -u centos -- private-key <key.pem> --extra-vars="os=CentOS7 pg_version=10 pg_typeE=PG"
ansible-playbook playbook.yml -u centos -- private-key <key.pem> --extra-vars="os=CentOS7 pg_version=11 pg_type=PG"
ansible-playbook playbook.yml -u centos -- private-key <key.pem> --extra-vars="os=CentOS7 pg_version=12 pg_type=PG"
ansible-playbook playbook.yml -u centos -- private-key <key.pem> --extra-vars="OS=CentOS7 PG_VERSION=10 PG_TYPE=PG"
ansible-playbook playbook.yml -u centos -- private-key <key.pem> --extra-vars="OS=CentOS7 PG_VERSION=11 PG_TYPE=PG"
ansible-playbook playbook.yml -u centos -- private-key <key.pem> --extra-vars="OS=CentOS7 PG_VERSION=12 PG_TYPE=PG"

CentOS 7: EDB Advanced Server with command line parameters
CentOS 7: Enterprise Postgresql with command line parameters
----------------


ansible-playbook playbook.yml -u centos -- private-key <key.pem> --extra-vars="os=CentOS7 pg_version=10 pg_type=EPAS"
ansible-playbook playbook.yml -u centos -- private-key <key.pem> --extra-vars="os=CentOS7 pg_version=11 pg_type=EPAS"
ansible-playbook playbook.yml -u centos -- private-key <key.pem> --extra-vars="os=CentOS7 pg_version=12 pg_type=EPAS"
ansible-playbook playbook.yml -u centos -- private-key <key.pem> --extra-vars="OS=CentOS7 PG_VERSION=10 PG_TYPE=EPAS"
ansible-playbook playbook.yml -u centos -- private-key <key.pem> --extra-vars="OS=CentOS7 PG_VERSION=11 PG_TYPE=EPAS"
ansible-playbook playbook.yml -u centos -- private-key <key.pem> --extra-vars="OS=CentOS7 PG_VERSION=12 PG_TYPE=EPAS"


RHEL 7: Community Postgresql with command line parameters
----------------


ansible-playbook playbook.yml -u ec2-user -- private-key <key.pem> --extra-vars="os=RHEL7 pg_version=10 pg_type=PG"
ansible-playbook playbook.yml -u ec2-user -- private-key <key.pem> --extra-vars="os=RHEL7 pg_version=11 pg_type=PG"
ansible-playbook playbook.yml -u ec2-user -- private-key <key.pem> --extra-vars="os=RHEL7 pg_version=12 pg_type=PG"
ansible-playbook playbook.yml -u ec2-user -- private-key <key.pem> --extra-vars="OS=RHEL7 PG_VERSION=10 PG_TYPE=PG"
ansible-playbook playbook.yml -u ec2-user -- private-key <key.pem> --extra-vars="OS=RHEL7 PG_VERSION=11 PG_TYPE=PG"
ansible-playbook playbook.yml -u ec2-user -- private-key <key.pem> --extra-vars="OS=RHEL7 PG_VERSION=12 PG_TYPE=PG"


RHEL 7: Enterprise Postgresql with command line parameters
----------------


ansible-playbook playbook.yml -u ec2-user -- private-key <key.pem> --extra-vars="os=RHEL7 pg_version=10 pg_type=EPAS"
ansible-playbook playbook.yml -u ec2-user -- private-key <key.pem> --extra-vars="os=RHEL7 pg_version=11 pg_type=EPAS"
ansible-playbook playbook.yml -u ec2-user -- private-key <key.pem> --extra-vars="os=RHEL7 pg_version=12 pg_type=EPAS"
ansible-playbook playbook.yml -u ec2-user -- private-key <key.pem> --extra-vars="OS=RHEL7 PG_VERSION=10 PG_TYPE=EPAS"
ansible-playbook playbook.yml -u ec2-user -- private-key <key.pem> --extra-vars="OS=RHEL7 PG_VERSION=11 PG_TYPE=EPAS"
ansible-playbook playbook.yml -u ec2-user -- private-key <key.pem> --extra-vars="OS=RHEL7 PG_VERSION=12 PG_TYPE=EPAS"


CentOS 7: Community Postgresql without command line parameters
Expand Down
186 changes: 115 additions & 71 deletions roles/init_dbserver/defaults/main.yml
Original file line number Diff line number Diff line change
@@ -1,74 +1,118 @@
---
# postgres settings
os: ""
pg_type: PG
pg_version: 12
pg_ssl: true

force_initdb: false
use_hostname: false

pass_dir: "~/.edb"

pg_wal: ""
pg_data: "/var/lib/pgsql/{{ pg_version }}/data"
pg_default_data: "/var/lib/pgsql/{{ pg_version }}/data"
pg_encoding: ""

# log directory and filename
pg_log: "/var/log/postgres"
pg_log_filename: "postgresql-%a.log"

# postgres service
pg_service: "postgresql-{{ pg_version }}"

# required & optional directories
pg_user_home: "/var/lib/pgsql"
pg_bin_path: "/usr/pgsql-{{ pg_version }}/bin"
pg_initdb: "{{ pg_bin_path }}/postgresql-{{ pg_version }}-setup initdb"
pg_initdb_options: "--encoding=UTF-8 --locale=en_US.UTF-8 --auth=peer --auth-local=scram-sha-256 --auth-host=scram-sha-256 --data-checksums"

# unix socket domain directories
pg_unix_socket_directories:
# Postgres Settings
OS: ""
PG_TYPE: "PG"
PG_VERSION: "12"
PG_SSL: True
PG_SSL_DIR: "/etc/edb/certs"
PG_SSL_GENERATE: True

FORCE_INITIALIZE: false
USE_HOSTNAME: False

USER_HOMEDIR: "~/"

PG_WAL: ""
PG_DATA: "/var/lib/pgsql/{{ PG_VERSION }}/data"
PG_DEFAULT_DATA: "/var/lib/pgsql/{{ PG_VERSION }}/data"
PG_ENCODING: "UTF-8"
# Encoding details
PG_LOCALE: "en_US"
PG_CTYPE: "{{ postgresql_ctype_parts | join('.') }}"

# Log directory and Filename
PG_LOG: "/var/log/postgres"
PG_LOG_FILENAME: "postgresql-%a.log"

# Databases
PG_DATABASES: []
# List of Databases Example
#PG_DATABASES:
# - name: pgdatabase

# Users
PG_USERS: []
# List of Users Example
#PG_USERS:
#- name: pg1
# pass: pg1
# encrypted: yes

# Postgres Service
PG_SERVICE: "postgresql-{{ PG_VERSION }}"

# Required & optional directories
PG_USER_HOME: "/var/lib/pgsql"
PG_BIN_PATH: "/usr/pgsql-{{ PG_VERSION }}/bin"
PG_INITDB: "{{ PG_BIN_PATH }}/initdb --auth=peer --auth-host=scram-sha-256"
PG_INITDB_OPTIONS: " --data-checksums "

# Unix socket domain directories
PG_UNIX_SOCKET_DIRECTORIES:
- "/var/run/postgresql"

# postgres port
pg_port: 5432

# postgres database
pg_database: "postgres"

# postgres user
pg_owner: "postgres"
pg_group: "postgres"

# postgres superuser
pg_superuser: "postgres"
pg_superuser_password: ""
pg_random_password: true

# Input variables
input _user: ""
input_password: ""

etc_hosts_lists: []

supported_os:
- CentOS7
- CentOS8
- RHEL7
- RHEL8

supported_pg_type:
- EPAS
- PG

supported_pg_version:
- 10
- 11
- 12
- 13

supported_node_type:
- primary
- pemserver
# Postgres Port
PG_PORT: 5432

# Postgres Database
PG_DATABASE: "postgres"

# Postgres User
PG_OWNER: "postgres"
PG_GROUP: "postgres"

# Postgres SuperUser
PG_SUPERUSER: "postgres"
PG_SUPERUSER_PASSWORD: ""
PG_RANDOM_PASSWORD: false

# Global configuration options that will be set via ALTER SYSTEM in postgresql.auto.conf
PG_POSTGRES_DEFAULT_CONF_PARAMS:
- {name: "unix_socket_directories", value: "{{ PG_UNIX_SOCKET_DIRECTORIES | join(',') }}"}
- {name: "listen_addresses", value: "*" }
- { name: wal_level, value: replica }
- { name: max_wal_senders, value: 10 }
- { name: hot_standby, value: on }
- { name: max_replication_slots, value: 10 }
- { name: wal_compression, value: on }
- { name: wal_log_hints, value: on }
- { name: checkpoint_timeout, value: 15min }
- { name: checkpoint_completion_target, value: 0.9 }
- { name: archive_mode, value: on }
- { name: archive_command, value: '/bin/true' }
- { name: random_page_cost, value: 1.1 }
- { name: cpu_tuple_cost, value: 0.03 }
- { name: logging_collector, value: on }
- { name: log_line_prefix, value: '%m [%p-%l] %u@%d app=%a ' }
- { name: log_truncate_on_rotation, value: on }
- { name: log_rotation_size, value: '1GB' }
- { name: log_lock_waits, value: on }
- { name: log_connections, value: on }
- { name: log_disconnections, value: on }
- { name: log_error_verbosity, value: default }
- { name: log_statement, value: ddl }
- { name: log_temp_files, value: 0 }
- { name: log_autovacuum_min_duration, value: 0 }
- { name: autovacuum_max_workers, value: 5 }
- { name: autovacuum_vacuum_cost_limit, value: 3000 }
- { name: idle_in_transaction_session_timeout, value: 10min }
- { name: syslog_ident, value: postgres }

PG_POSTGRES_CONF_PARAMS: ""
PG_ALLOW_IP_ADDRESSES: ""
PG_EXTENSIONS: ""
PG_SHARED_LIBRARIES_LIST: ""

PG_GRANT_PRIVILEGES: ""
PG_GRANT_ROLES: ""
#PG_GRANT_PRIVILEGES:
# - { "type": "function", "grant": yes, "privileges": "EXECUTE", "schema": "pg_catalog", "objects": "pg_current_wal_lsn(),pg_last_wal_replay_lsn(),pg_wal_replay_resume(),pg_wal_replay_pause()", "roles": "rewinduser", "database": "edb" }
#PG_GRANT_ROLES:
# - { "role": "pg_monitor", "user": "efm", "grant": yes }
PG_SQL_SCRIPTS: ""
# - {"file_path": "/usr/edb/as12/share/edb-sample.sql", db: "dbname"}

PG_COPY_SQL_SCRIPTS: ""
# - {"file": "/tmp/sample.sql", "remote_file": "/usr/edb/as12/share", "owner": "owner", "group": "group", "mode": "mode" }
#
ETC_HOSTS_LISTS: ""
28 changes: 28 additions & 0 deletions roles/init_dbserver/tasks/C07-RH07-check-service.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
---

- name: Check if Cluster has been initialized
shell: |
#/bin/bash
systemctl is-active --quiet {{ PG_SERVICE }} \
&& echo "service_running" || echo "service_not_running"
args:
executable: /bin/bash
changed_when: "'service_not_running' in service_status.stdout"
become: yes
register: service_status

- name: Check if Cluster has been initialized
stat:
path: "{{ PG_DATA }}/PG_VERSION"
become: yes
register: pgdata_file

- name: Verify PGDATA and stop if exists
fail:
msg: "It looks like either {{ PG_DATA }} directory is not empty or Service is running
without {{ PG_DATA }} as directory. Take he backup of existing {{ PG_DATA }}
and stop the service to proceed for intialize.
Or use force_initialize option"
when:
- ( pgdata_file.stat.exists and service_status.stdout != 'service_running' )
- ( not pgdata_file.stat.exists and service_status.stdout == 'service_running' )
Loading

0 comments on commit e789e9d

Please sign in to comment.