2017-05-16 19:04:19 +02:00
- name : Download postgresql rpm
get_url :
url : https://download.postgresql.org/pub/repos/yum/9.6/redhat/rhel-7-x86_64/pgdg-centos96-9.6-3.noarch.rpm
dest : /tmp/postgresql.rpm
- name : Install postgresql.rpm
yum :
name : "{{ item }}"
state : present
become : true
with_items :
- /tmp/postgresql.rpm
2017-05-07 22:31:38 +02:00
- name : Install postgresql
yum :
2017-05-08 16:49:51 +02:00
name : "{{ item }}"
2017-05-07 22:31:38 +02:00
state : present
become : true
2017-05-08 16:49:51 +02:00
with_items :
2017-05-16 19:04:19 +02:00
- postgresql96-server
- postgresql96-contrib # Needed for extensions (ie : btree_gin)
- pgpool-II-96
- name : Add go to PATH
lineinfile :
path : ~/.bashrc
regexp : 'export PATH=.*pgsql.*'
line : 'export PATH=$PATH:/usr/pgsql-9.6/bin'
2017-05-07 22:31:38 +02:00
- name : Initialize postgresql
2017-05-16 19:04:19 +02:00
command : /usr/pgsql-9.6/bin/initdb -D /var/lib/pgsql/9.6/data
2017-05-07 22:31:38 +02:00
# Will error when database has already been initialized so just ignore it
ignore_errors : yes
become : true
2017-05-16 19:04:19 +02:00
become_user : postgres
- name : Copy configuration file for postgresql
template :
src : postgresql.conf.j2
dest : /var/lib/pgsql/9.6/data/postgresql.conf
become : true
become_user : postgres
2017-05-07 22:31:38 +02:00
- name : Install adapter for python
yum :
name : python-psycopg2
state : present
become : true
2017-05-08 16:49:51 +02:00
- name : Configure pgpool
template :
src : pgpool.conf.j2
2017-05-16 19:04:19 +02:00
dest : /etc/pgpool-II-96/pgpool.conf
2017-05-08 16:49:51 +02:00
become : true
2017-05-09 05:38:37 +02:00
- name : Create oiddir for pgpool
file :
path : "{{ memqcache_oiddir }}"
state : directory
become : true
2017-05-16 19:04:19 +02:00
- name : Fix bug where pid is in wrong pool
file :
src : /var/run/pgpool-II-96
path : /var/run/pgpool
state : link
force : yes
become : true
2017-05-08 16:49:51 +02:00
- name : Start postgresql, pgpool and enable at boot
2017-05-07 22:31:38 +02:00
systemd :
enabled : yes
2017-05-08 16:49:51 +02:00
name : "{{ item }}"
2017-05-07 22:31:38 +02:00
state : started
become : true
2017-05-08 16:49:51 +02:00
with_items :
2017-05-16 19:04:19 +02:00
- postgresql-9.6
- pgpool-II-96
2017-05-07 22:31:38 +02:00
- name : Create nyaapantsu database
postgresql_db :
name : "{{ nyaapantsu_dbname }}"
become : true
become_user : postgres
# TODO Probably better idea to not set SUPERUSER
- name : Create nyaapantsu user
postgresql_user :
db : "{{ nyaapantsu_dbname }}"
name : "{{ nyaapantsu_user }}"
password : "{{ nyaapantsu_password }}"
role_attr_flags : SUPERUSER,LOGIN
become : true
become_user : postgres
- name : Grant privileges to user
postgresql_privs :
db : "{{ nyaapantsu_dbname }}"
priv : ALL
roles : "{{ nyaapantsu_user }}"
state : present
type : database
become : true
become_user : postgres
- name : Add custom pg_hba.conf
template :
src : pg_hba.conf.j2
2017-05-16 19:04:19 +02:00
dest : /var/lib/pgsql/9.6/data/pg_hba.conf
2017-05-07 22:31:38 +02:00
become : true
become_user : postgres
2017-05-08 03:44:36 +02:00
- name : Add .pgpass
template :
src : pgpass.j2
dest : ~/.pgpass
mode : 0600
2017-05-07 22:31:38 +02:00
- name : Reload postgres
systemd :
2017-05-16 19:04:19 +02:00
name : postgresql-9.6
2017-05-07 22:31:38 +02:00
state : reloaded
become : true