library/roles/data_disk/tasks/main.yml: Ansible 2 compatibility.

library/roles/postgresql: Ansible 2 compatibility.
library/roles/postgresql/tasks/manage_pg_db.yml: Add a task that activates extensions on the databases.
This commit is contained in:
Andrea Dell'Amico 2016-03-07 17:43:37 +01:00
parent 075f946517
commit 123af8c4ea
9 changed files with 37 additions and 23 deletions

View File

@ -1,7 +1,7 @@
---
- name: Create a file system on the new disks
filesystem: dev=/dev/{{ item.device }} fstype={{ item.fstype }} force=no
with_items: disks_and_mountpoints_list
with_items: '{{ disks_and_mountpoints_list | default([]) }}'
when:
- additional_disks
- item.create_filesystem
@ -9,7 +9,7 @@
- name: Manage the additional file systems
mount: name={{ item.mountpoint }} src=/dev/{{ item.device }} fstype={{ item.fstype }} opts={{ item.opts }} state={{ item.state }}
with_items: '{{ disks_and_mountpoints_list }}'
with_items: '{{ disks_and_mountpoints_list | default([]) }}'
when: additional_disks
tags: [ 'data_disk', 'mountpoint' ]

View File

@ -1,11 +1,11 @@
---
pg_use_postgresql_org_repo: True
psql_postgresql_install: True
psql_pkg_state: installed
postgresql_enabled: True
psql_pgpool_install: False
psql_pgpool_service_install: False
psql_pgpool_pkg_state: installed
# 9.3 is the default version for Ubuntu trusty
# It is highly recommended to use the postgresql.org repositories
@ -44,6 +44,9 @@ postgresql_pkgs:
- 'postgresql-client-{{ psql_version }}'
- pgtop
psql_ansible_needed_pkgs:
- python-psycopg2
# - libpq-dev
psql_db_name: db_name
psql_db_user: db_user
psql_db_pwd: "We cannot save the password into the repository. Use another variable and change pgpass.j2 accordingly. Encrypt the file that contains the variable with ansible-vault"
@ -62,7 +65,7 @@ postgres_gis_version: 2.1
postgres_gis_pkgs:
- 'postgresql-{{ psql_version }}-postgis-{{ postgres_gis_version }}'
# Local backup
pg_backup_enabled: True
pg_backup_bin: /usr/local/sbin/postgresql-backup
pg_backup_pgdump_bin: /usr/bin/pg_dump
@ -79,7 +82,7 @@ pg_backup_use_nagios: "yes"
#psql_db_data:
# Example of line needed to create a db, create the user that owns the db, manage the db accesses (used by iptables too). All the fields are mandatory.
#- { name: '{{ psql_db_name }}', encoding: 'UTF8', user: '{{ psql_db_user }}', pwd: '{{ psql_db_pwd }}', roles: 'NOCREATEDB,NOSUPERUSER', allowed_hosts: [ 'xxx.xxx.xxx.xxx/32', 'yyy.yyy.yyy.yyy/32' ] }
#- { name: '{{ psql_db_name }}', encoding: 'UTF8', user: '{{ psql_db_user }}', pwd: '{{ psql_db_pwd }}', roles: 'NOCREATEDB,NOSUPERUSER', extensions: [ 'postgis', 'pgpool_regclass', 'pgpool_recovery' ], allowed_hosts: [ 'xxx.xxx.xxx.xxx/32', 'yyy.yyy.yyy.yyy/32' ] }
# Example of line needed to manage the db accesses (used by iptables too), without creating the db and the user. Useful, for example, to give someone access to the postgresql db
#- { name: '{{ psql_db_name }}', user: '{{ psql_db_user }}', allowed_hosts: [ 'xxx.xxx.xxx.xxx/32', 'yyy.yyy.yyy.yyy/32' ] }

View File

@ -8,8 +8,8 @@
- name: Give access to the remote postgresql client
lineinfile: name=/etc/postgresql/{{ psql_version }}/main/pg_hba.conf regexp="^host {{ item.0.name }} {{ item.0.user }} {{ item.1 }}.*$" line="host {{ item.0.name }} {{ item.0.user }} {{ item.1 }} md5"
with_subelements:
- '{{ psql_db_data }}'
- '{{ allowed_hosts }}'
- '{{ psql_db_data | default([]) }}'
- allowed_hosts
when:
- psql_listen_on_ext_int
- psql_db_data is defined

View File

@ -5,6 +5,8 @@
when: psql_postgresql_install
- include: postgis.yml
when: postgres_install_gis_extensions
- include: postgres_pgpool.yml
when: psql_pgpool_install
- include: postgresql-config.yml
when: psql_postgresql_install
- include: psql-kernel-sharedmem.yml
@ -24,5 +26,7 @@
- psql_postgresql_install
- psql_db_data is defined
- include: pgpool-ii.yml
when: psql_pgpool_install
when: psql_pgpool_service_install

View File

@ -18,3 +18,13 @@
- psql_db_data is defined
- ( item.createdb is not defined or item.createdb )
tags: [ 'postgresql', 'postgres', 'pg_db' ]
- name: Add postgres extensions to the databases, if needed
become: True
become_user: postgres
postgresql_ext: name={{ item.1 }} db={{ item.0.name }}
with_subelements:
- '{{ psql_db_data | default ([]) }}'
- extensions
when: item.1 is defined
tags: [ 'postgresql', 'postgres', 'pg_extensions' ]

View File

@ -7,16 +7,9 @@
- name: Install the packages that ansible needs to manage the postgresql users and databases
apt: pkg={{ item }} state={{ psql_pkg_state }}
with_items:
- python-psycopg2
with_items: '{{ psql_ansible_needed_pkgs }}'
tags: [ 'postgresql', 'postgres' ]
- 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
tags: [ 'postgresql', 'postgres', 'pgpool' ]
- name: Ensure that the postgresql server is started
service: name=postgresql state=started enabled=yes
when: postgresql_enabled

View File

@ -2,9 +2,6 @@
- name: install the postgresql GIS packages
apt: pkg={{ item }} state={{ psql_pkg_state }}
with_items: '{{ postgres_gis_pkgs }}'
notify:
Restart postgresql
tags:
- postgresql
- postgres
notify: Restart postgresql
tags: [ 'postgresql', 'postgres', 'postgis' ]

View File

@ -0,0 +1,8 @@
---
- 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' ]

View File

@ -60,7 +60,6 @@
- name: Install additional packages, if any
apt: pkg={{ item }} state={{ pkg_state }}
with_items: '{{ additional_packages }}'
when: additional_packages is defined
with_items: '{{ additional_packages | default([]) }}'
tags: [ 'packages', 'common_pkgs', 'additional_packages' ]