From c0be314268792d316cedcb3db3b476dcb06748c9 Mon Sep 17 00:00:00 2001 From: Kris Lamoureux Date: Thu, 26 May 2022 23:49:06 -0400 Subject: [PATCH] Add PostgreSQL server role --- ansible.cfg | 3 +++ dev/proxy.yml | 3 ++- roles/.gitignore | 1 + roles/base/tasks/ansible.yml | 7 ++++++ roles/postgresql/defaults/main.yml | 2 ++ roles/postgresql/tasks/main.yml | 34 ++++++++++++++++++++++++++++++ 6 files changed, 49 insertions(+), 1 deletion(-) create mode 100644 roles/postgresql/defaults/main.yml create mode 100644 roles/postgresql/tasks/main.yml diff --git a/ansible.cfg b/ansible.cfg index f237d47..e0ac21f 100644 --- a/ansible.cfg +++ b/ansible.cfg @@ -1,3 +1,6 @@ [defaults] inventory = ./environments/development interpreter_python = /usr/bin/python3 + +[connection] +pipelining = true diff --git a/dev/proxy.yml b/dev/proxy.yml index 8df84cb..bd011b8 100644 --- a/dev/proxy.yml +++ b/dev/proxy.yml @@ -5,7 +5,8 @@ - host_vars/proxy.yml roles: - base + - postgresql - proxy - docker - - bitwarden - gitea + - bitwarden diff --git a/roles/.gitignore b/roles/.gitignore index a050612..c5edb12 100644 --- a/roles/.gitignore +++ b/roles/.gitignore @@ -10,6 +10,7 @@ !minecraft*/ !nextcloud*/ !nginx*/ +!postgresql*/ !prometheus*/ !proxy*/ !rsnapshot*/ diff --git a/roles/base/tasks/ansible.yml b/roles/base/tasks/ansible.yml index 16ae819..37922de 100644 --- a/roles/base/tasks/ansible.yml +++ b/roles/base/tasks/ansible.yml @@ -13,3 +13,10 @@ loop: - aptitude - python3-docker + - python3-psycopg2 + +- name: Create Ansible's temporary remote directory + file: + path: "~/.ansible/tmp" + state: directory + mode: 0700 diff --git a/roles/postgresql/defaults/main.yml b/roles/postgresql/defaults/main.yml new file mode 100644 index 0000000..e9af37e --- /dev/null +++ b/roles/postgresql/defaults/main.yml @@ -0,0 +1,2 @@ +postgresql_config: /etc/postgresql/13/main/pg_hba.conf +postgresql_listen: "*" diff --git a/roles/postgresql/tasks/main.yml b/roles/postgresql/tasks/main.yml new file mode 100644 index 0000000..4f6ed71 --- /dev/null +++ b/roles/postgresql/tasks/main.yml @@ -0,0 +1,34 @@ +- name: Install PostgreSQL + apt: + name: postgresql + state: present + +- name: Trust connections to PostgreSQL from Docker + postgresql_pg_hba: + dest: "{{ postgresql_config }}" + contype: host + databases: all + users: all + address: "172.16.0.0/12" + method: trust + register: postgresql_hba + +- name: Change PostgreSQL listen addresses + postgresql_set: + name: listen_addresses + value: "{{ postgresql_listen }}" + become: true + become_user: postgres + register: postgresql_config + +- name: Reload PostgreSQL + service: + name: postgresql + state: reloaded + when: postgresql_hba.changed and not postgresql_config.changed + +- name: Restart PostgreSQL + service: + name: postgresql + state: restarted + when: postgresql_config.changed