Skip to content

Commit

Permalink
Merge pull request #111 from EnterpriseDB/REL-3_0_0
Browse files Browse the repository at this point in the history
Merge the fixes from Release 3.0.0 to master branch
  • Loading branch information
vibhorkumar123 authored Jan 11, 2021
2 parents e231cb9 + 1b8d3cf commit b8e090c
Show file tree
Hide file tree
Showing 36 changed files with 253 additions and 230 deletions.
21 changes: 15 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,18 +1,24 @@
# This Makefile helps to build and publish the Ansible collection on the Galaxy platform
# This Makefile helps to build, install or publish the Ansible
# collection on the Galaxy platform.
# Target version can be passed with the EDB_ANSIBLE_VERSION env.
# variable. The default version is taken from the VERSION file
# content.
#
# Build the collection:
# make EDB_ANSIBLE_VERSION=x.y.z build
# make build
#
# Publish the collection once it has been built:
# make EDB_ANSIBLE_VERSION=x.y.z API_KEY=xxxxxxxx publish
# make API_KEY=xxxxxxxx publish
# Note: the API key can be found at https://galaxy.ansible.com/me/preferences
#
# Clean up the generated files:
# make EDB_ANSIBLE_VERSION=x.y.z clean

EDB_ANSIBLE_VERSION ?= 3.0.0
# make clean
#
# Clean up, build and install the collection:
# make install

DIR := $(shell dirname $(realpath $(firstword $(MAKEFILE_LIST))))
EDB_ANSIBLE_VERSION ?= $(shell cat $(DIR)/VERSION)

build:
sed -E 's/version:.*/version: "$(EDB_ANSIBLE_VERSION)"/g' $(DIR)/galaxy.template.yml > $(DIR)/galaxy.yml
Expand All @@ -24,3 +30,6 @@ publish:
clean:
rm -f $(DIR)/galaxy.yml
rm -f $(DIR)/edb_devops-edb_postgres-$(EDB_ANSIBLE_VERSION).tar.gz

install: clean build
ansible-galaxy collection install $(DIR)/edb_devops-edb_postgres-$(EDB_ANSIBLE_VERSION).tar.gz --force
74 changes: 55 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,8 @@ By default the location of your installed collection is:

### Downloading the `edb-ansible` repository source code from the repository in GitHub

This method requires to have the `ansible-galaxy` tool installed.

Downloading the code from the repository can be accomplished by following the
steps below:

Expand All @@ -226,11 +228,27 @@ steps below:
After the code has been downloaded, the code will be available as a zip file
which requires being unzipped to your desired target destination.

**WARNING**: This approach does not automatically make the `edb_postgres`
collection available to your playbooks.
After the code has been unzipped, you must go to root folder
`edb-ansible-master`, and install the collection by entering the command below:

```bash
$ make install
```

This approach automatically makes the `edb_postgres` collection available to
your playbooks.

A message indicating where the collection is installed will be displayed by
ansible-galaxy. The collection code should be automatically made readily
available for you.

By default the location of your installed collection is:
`~/.ansible/collections/ansible_collections`

### Cloning the `edb-ansible` repository source code from the repository GitHub

This method requires to have the `ansible-galaxy` tool installed.

Downloading the code from the repository can be accomplished by following the
steps below:

Expand All @@ -247,8 +265,21 @@ You can access the root folder of the repository by entering the command below:
$ cd edb-ansible
```

**WARNING**: This approach does not automatically make the `edb_postgres`
collection available to your playbooks.
You can install the collection by entering the command below:

```bash
$ make install
```

This approach automatically makes the `edb_postgres` collection available to
your playbooks.

A message indicating where the collection is installed will be displayed by
ansible-galaxy. The collection code should be automatically made readily
available for you.

By default the location of your installed collection is:
`~/.ansible/collections/ansible_collections`

## Inventory file content

Expand Down Expand Up @@ -300,9 +331,8 @@ playbook:
become: yes
gather_facts: yes
# When using collections
#collections:
# - edb_devops.edb_postgres
collections:
- edb_devops.edb_postgres
pre_tasks:
- name: Initialize the user defined variables
Expand All @@ -315,29 +345,35 @@ playbook:
roles:
- role: setup_repo
when: "'setup_repo' in host_supported_roles"
when: "'setup_repo' in lookup('edb_devops.edb_postgres.supported_roles')"
- role: install_dbserver
when: "'install_dbserver' in host_supported_roles"
when: "'install_dbserver' in lookup('edb_devops.edb_postgres.supported_roles')"
- role: init_dbserver
when: "'init_dbserver' in host_supported_roles"
when: "'init_dbserver' in lookup('edb_devops.edb_postgres.supported_roles')"
- role: setup_replication
when: "'setup_replication' in host_supported_roles"
when: "'setup_replication' in lookup('edb_devops.edb_postgres.supported_roles')"
- role: setup_efm
when: "'setup_efm' in host_supported_roles"
when: "'setup_efm' in lookup('edb_devops.edb_postgres.supported_roles')"
- role: setup_pgpool2
when: "'setup_pgpool2' in host_supported_roles"
when: "'setup_pgpool2' in lookup('edb_devops.edb_postgres.supported_roles')"
- role: manage_pgpool2
when: "'manage_pgpool2' in host_supported_roles"
when: "'manage_pgpool2' in lookup('edb_devops.edb_postgres.supported_roles')"
- role: manage_dbserver
when: "'manage_dbserver' in host_supported_roles"
when: "'manage_dbserver' in lookup('edb_devops.edb_postgres.supported_roles')"
- role: setup_pemserver
when: "'setup_pemserver' in host_supported_roles"
when: "'setup_pemserver' in lookup('edb_devops.edb_postgres.supported_roles')"
- role: setup_pemagent
when: "'setup_pemagent' in host_supported_roles"
when: "'setup_pemagent' in lookup('edb_devops.edb_postgres.supported_roles')"
- role: setup_pgbouncer
when: "'setup_pgbouncer' in host_supported_roles"
when: "'setup_pgbouncer' in lookup('edb_devops.edb_postgres.supported_roles')"
- role: manage_pgbouncer
when: "'manage_pgbouncer' in host_supported_roles"```
when: "'manage_pgbouncer' in lookup('edb_devops.edb_postgres.supported_roles')"
- role: setup_barmanserver
when: "'setup_barmanserver' in lookup('edb_devops.edb_postgres.supported_roles')"
- role: setup_barman
when: "'setup_barman' in lookup('edb_devops.edb_postgres.supported_roles')"
- role: autotuning
when: "'autotuning' in lookup('edb_devops.edb_postgres.supported_roles')"
```

You can customize the above example to install Postgres, EPAS, EFM or PEM or
Expand Down
1 change: 1 addition & 0 deletions VERSION
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.0.0
35 changes: 17 additions & 18 deletions playbook.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@
become: yes
gather_facts: yes

# When using collections
#collections:
# - edb_devops.edb_postgres
collections:
- edb_devops.edb_postgres

pre_tasks:
- name: Initialize the user defined variables
Expand All @@ -19,32 +18,32 @@

roles:
- role: setup_repo
when: "'setup_repo' in host_supported_roles"
when: "'setup_repo' in lookup('edb_devops.edb_postgres.supported_roles')"
- role: install_dbserver
when: "'install_dbserver' in host_supported_roles"
when: "'install_dbserver' in lookup('edb_devops.edb_postgres.supported_roles')"
- role: init_dbserver
when: "'init_dbserver' in host_supported_roles"
when: "'init_dbserver' in lookup('edb_devops.edb_postgres.supported_roles')"
- role: setup_replication
when: "'setup_replication' in host_supported_roles"
when: "'setup_replication' in lookup('edb_devops.edb_postgres.supported_roles')"
- role: setup_efm
when: "'setup_efm' in host_supported_roles"
when: "'setup_efm' in lookup('edb_devops.edb_postgres.supported_roles')"
- role: setup_pgpool2
when: "'setup_pgpool2' in host_supported_roles"
when: "'setup_pgpool2' in lookup('edb_devops.edb_postgres.supported_roles')"
- role: manage_pgpool2
when: "'manage_pgpool2' in host_supported_roles"
when: "'manage_pgpool2' in lookup('edb_devops.edb_postgres.supported_roles')"
- role: manage_dbserver
when: "'manage_dbserver' in host_supported_roles"
when: "'manage_dbserver' in lookup('edb_devops.edb_postgres.supported_roles')"
- role: setup_pemserver
when: "'setup_pemserver' in host_supported_roles"
when: "'setup_pemserver' in lookup('edb_devops.edb_postgres.supported_roles')"
- role: setup_pemagent
when: "'setup_pemagent' in host_supported_roles"
when: "'setup_pemagent' in lookup('edb_devops.edb_postgres.supported_roles')"
- role: setup_pgbouncer
when: "'setup_pgbouncer' in host_supported_roles"
when: "'setup_pgbouncer' in lookup('edb_devops.edb_postgres.supported_roles')"
- role: manage_pgbouncer
when: "'manage_pgbouncer' in host_supported_roles"
when: "'manage_pgbouncer' in lookup('edb_devops.edb_postgres.supported_roles')"
- role: setup_barmanserver
when: "'setup_barmanserver' in host_supported_roles"
when: "'setup_barmanserver' in lookup('edb_devops.edb_postgres.supported_roles')"
- role: setup_barman
when: "'setup_barman' in host_supported_roles"
when: "'setup_barman' in lookup('edb_devops.edb_postgres.supported_roles')"
- role: autotuning
when: "'autotuning' in host_supported_roles"
when: "'autotuning' in lookup('edb_devops.edb_postgres.supported_roles')"
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
109 changes: 109 additions & 0 deletions plugins/lookup/supported_roles.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type

DOCUMENTATION = """
name: supported_roles
author: Julien Tachoires
short_description: Get the list of the supported roles by the current host
description:
- "Get the list of the supported roles byt the current host, based on its
groups and attributes."
"""

EXAMPLES = """
- name: Get the supported roles by the current host
debug: msg="{{ lookup('supported_roles') }}"
"""

RETURN = """
_value:
description:
- List of role name
type: list
elements:
- string
"""

from ansible.errors import AnsibleError
from ansible.plugins.lookup import LookupBase

GROUP_ROLES = {
'primary': [
'setup_repo',
'install_dbserver',
'init_dbserver',
'manage_dbserver',
'setup_efm',
'autotuning'
],
'standby': [
'setup_repo',
'install_dbserver',
'setup_replication',
'manage_dbserver',
'setup_efm',
'autotuning'
],
'pemserver': [
'setup_repo',
'install_dbserver',
'init_dbserver',
'manage_dbserver',
'setup_pemserver',
'autotuning'
],
'pgbouncer': [
'setup_repo',
'setup_pgbouncer',
'manage_pgbouncer'
],
'pgpool2': [
'setup_repo',
'setup_pgpool2',
'manage_pgpool2'
],
'barmanserver': [
'setup_repo',
'setup_barmanserver',
'install_dbserver'
]
}

class LookupModule(LookupBase):
def run(self, terms, variables=None, **kwargs):
supported_roles = []
# Inventory hostname
hostname = variables['inventory_hostname']

myvars = getattr(self._templar, '_available_variables', {})

for group in variables['group_names']:
supported_roles = list(
set(supported_roles)
| set(GROUP_ROLES.get(group, []))
)
# Special case for the primary or standby nodes when the host
# variable pgbouncer is set to true.
if (group in ['primary', 'standby']
and myvars['hostvars'][hostname].get('pgbouncer', False)):
supported_roles = list(
set(supported_roles)
| set(['setup_pgbouncer', 'manage_pgbouncer'])
)
# Special case for the primary or standby nodes when the
# host variable pem_agent is set to true.
if (group in ['primary', 'standby']
and myvars['hostvars'][hostname].get('pem_agent', False)):
supported_roles = list(
set(supported_roles)
| set(['setup_pemagent'])
)
# Special case for the pemserver, primary or standby nodes when
# the host variable barman is set to true.
if (group in ['pemserver', 'primary', 'standby']
and myvars['hostvars'][hostname].get('barman', False)):
supported_roles = list(
set(supported_roles)
| set(['setup_barman'])
)
return supported_roles
5 changes: 2 additions & 3 deletions roles/autotuning/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,8 @@ Below is an example of how to include the `autotuning` role:
become: true
gather_facts: yes
# When using collections
#collections:
# - edb_devops.edb_postgres
collections:
- edb_devops.edb_postgres
pre_tasks:
- name: Initialize the user defined variables
Expand Down
2 changes: 2 additions & 0 deletions roles/autotuning/templates/tuned.conf.template
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@ min_perf_pct=100
readahead=>4096
elevator={{ tuned_disk_elevator }}
[sysctl]
{% if 'pemserver' not in group_names %}
vm.overcommit_memory=2
vm.swappiness=1
{% endif %}
vm.dirty_ratio=30
vm.dirty_background_ratio=10
[vm]
Expand Down
5 changes: 2 additions & 3 deletions roles/init_dbserver/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,8 @@ Below is an example of how to include the `init_dbserver` role:
become: yes
gather_facts: yes
# When using collections
#collections:
# - edb_devops.edb_postgres
collections:
- edb_devops.edb_postgres
pre_tasks:
- name: Initialize the user defined variables
Expand Down
2 changes: 1 addition & 1 deletion roles/init_dbserver/tasks/init_dbserver.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
- name: Gather the host and information for /etc/hosts
set_fact:
etc_hosts_lists: "{{ etc_hosts_lists + [node.private_ip + ' ' + node.hostname] }}"
loop: "{{ lookup('pg_sr_cluster_nodes', wantlist=True) }}"
loop: "{{ lookup('edb_devops.edb_postgres.pg_sr_cluster_nodes', wantlist=True) }}"
loop_control:
loop_var: node
when: use_hostname
Expand Down
5 changes: 2 additions & 3 deletions roles/install_dbserver/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,8 @@ Below is an example of how to include the `install_dbserver` role:
become: yes
gather_facts: yes
# When using collections
#collections:
# - edb_devops.edb_postgres
collections:
- edb_devops.edb_postgres
pre_tasks:
- name: Initialize the user defined variables
Expand Down
Loading

0 comments on commit b8e090c

Please sign in to comment.