summaryrefslogtreecommitdiff
path: root/ansible-continuous-delivery/roles/install-postgres/tasks/main.yml
diff options
context:
space:
mode:
authorAntoine Ouvrard <antoine.ouvrard@zextras.fr>2023-03-09 17:27:02 +0100
committerAntoine Ouvrard <antoine.ouvrard@zextras.fr>2023-03-09 17:27:02 +0100
commit749b7a84a0a7f74a3327ecad8110b2806a9d77e6 (patch)
treededbf8026a9ed2a6087ef99274fe7ddcea716215 /ansible-continuous-delivery/roles/install-postgres/tasks/main.yml
parent0495c4425e67eafe8e23aac49052564a6207ae27 (diff)
readd directory
Diffstat (limited to 'ansible-continuous-delivery/roles/install-postgres/tasks/main.yml')
-rw-r--r--ansible-continuous-delivery/roles/install-postgres/tasks/main.yml99
1 files changed, 99 insertions, 0 deletions
diff --git a/ansible-continuous-delivery/roles/install-postgres/tasks/main.yml b/ansible-continuous-delivery/roles/install-postgres/tasks/main.yml
new file mode 100644
index 0000000..7a80045
--- /dev/null
+++ b/ansible-continuous-delivery/roles/install-postgres/tasks/main.yml
@@ -0,0 +1,99 @@
+---
+- name: Vérification de la présence des paramètres d'entrées dans les variables
+ ansible.builtin.fail:
+ msg: |
+ La variable {{ item }} est obligatoire pour utiliser le role.
+ Veuillez la renseigner dans le dossier host_vars.
+ when:
+ - item is not defined
+ loop:
+ - db_user
+ - db_password
+ - db_name
+
+- name: Apt Update and Install Postgres
+ ansible.builtin.apt:
+ update_cache: true
+ name:
+ - postgresql
+ - acl
+ - python3-psycopg2
+ state: present
+ when: ansible_pkg_mgr == "apt"
+
+- name: Yum Update and Install Postgres
+ ansible.builtin.yum:
+ update_cache: true
+ name:
+ - postgresql
+ - postgresql-server
+ - postgresql-contrib
+ - acl
+ - python3-psycopg2
+ state: present
+ when: ansible_pkg_mgr == "yum"
+
+- name: Dnf Update and Install Postgres
+ ansible.builtin.dnf:
+ update_cache: true
+ name:
+ - postgresql
+ - postgresql-server
+ - postgresql-contrib
+ - acl
+ - python3-psycopg2
+ state: present
+ when: ansible_pkg_mgr == "dnf"
+
+- name: Yum/Dnf management
+ when: ansible_pkg_mgr == "dnf" or ansible_pkg_mgr == "yum"
+ block:
+ - name: Find out if PostgreSQL is initialized
+ ansible.builtin.stat:
+ path: "/var/lib/pgsql/data/pg_hba.conf"
+ register: postgres_data
+
+ - name: Init database only for Yum/Dnf OS
+ ansible.builtin.command: /usr/bin/postgresql-setup --initdb
+ when: not postgres_data.stat.exists
+
+- name: Start and enable services
+ ansible.builtin.service:
+ name: postgresql
+ state: started
+ enabled: true
+
+- name: Create db user
+ community.postgresql.postgresql_user:
+ state: present
+ name: "{{ db_user }}"
+ password: "{{ db_password }}"
+ role_attr_flags: CREATEDB
+ become: true
+ become_user: postgres
+
+- name: Allow md5 connection for the db user
+ community.postgresql.postgresql_pg_hba:
+ dest: "/etc/postgresql/12/main/pg_hba.conf"
+ contype: host
+ databases: all
+ method: md5
+ users: "{{ db_user }}"
+ create: true
+ become: true
+ become_user: postgres
+ notify: Restart postgres
+ when: ansible_pkg_mgr == "apt"
+
+- name: Allow md5 connection for the db user
+ community.postgresql.postgresql_pg_hba:
+ dest: "~/data/pg_hba.conf"
+ contype: host
+ databases: all
+ method: md5
+ users: "{{ db_user }}"
+ create: true
+ become: true
+ become_user: postgres
+ notify: Restart postgres
+ when: ansible_pkg_mgr == "dnf" or ansible_pkg_mgr == "yum"