Initial commit of PostgreSQL ansible role
Change-Id: Ieb82fed65ac8957058c4269182e1ea06f5bb87ee
diff --git a/tasks/Debian.yml b/tasks/Debian.yml
new file mode 100644
index 0000000..32e20bf
--- /dev/null
+++ b/tasks/Debian.yml
@@ -0,0 +1,33 @@
+---
+# postgresql tasks/Debian.yml
+#
+# SPDX-FileCopyrightText: © 2020 Open Networking Foundation <support@opennetworking.org>
+# SPDX-License-Identifier: Apache-2.0
+
+# Docs: https://www.postgresql.org/download/linux/ubuntu/
+- name: Add PostgreSQL apt repo key
+ apt_key:
+ data: "{{ lookup('file','ACCC4CF8.asc') }}"
+ state: "present"
+
+- name: Add Official PostgreSQL apt repo
+ apt_repository:
+ repo: "deb http://apt.postgresql.org/pub/repos/apt {{ ansible_lsb['codename'] }}-pgdg main"
+ mode: 0644
+ update_cache: true
+
+- name: Install PostgreSQL server, client, and python interface packages
+ apt:
+ name:
+ - "postgresql-{{ pgsql_version }}"
+ - "postgresql-client-{{ pgsql_version }}"
+ - "python3-psycopg2"
+ state: "present"
+ update_cache: true
+ cache_valid_time: 3600
+
+- name: Start and Enable PostgreSQL Service
+ service:
+ name: "{{ pgsql_service }}"
+ state: "started"
+ enabled: true
diff --git a/tasks/main.yml b/tasks/main.yml
new file mode 100644
index 0000000..bff685d
--- /dev/null
+++ b/tasks/main.yml
@@ -0,0 +1,33 @@
+---
+# postgresql tasks/main.yml
+#
+# SPDX-FileCopyrightText: © 2020 Open Networking Foundation <support@opennetworking.org>
+# SPDX-License-Identifier: Apache-2.0
+
+- name: include OS-specific vars
+ include_vars: "{{ ansible_os_family }}.yml"
+
+- name: include OS-specific tasks
+ include_tasks: "{{ ansible_os_family }}.yml"
+
+# docs: https://docs.ansible.com/ansible/latest/modules/postgresql_user_module.html
+# using no_log to not expose the user's postgres password at runtime, see docs:
+# https://docs.ansible.com/ansible/latest/reference_appendices/logging.html
+- name: Create PostgreSQL Database Users
+ postgresql_user:
+ name: "{{ item.name }}"
+ password: "{{ item.password }}"
+ with_items: "{{ pgsql_users }}"
+ no_log: true
+ become: true
+ become_user: "{{ pgsql_unix_username }}"
+
+# docs: https://docs.ansible.com/ansible/latest/modules/postgresql_db_module.html
+- name: Create Databases
+ postgresql_db:
+ name: "{{ item.name }}"
+ owner: "{{ item.owner }}"
+ template: "template1"
+ with_items: "{{ pgsql_databases }}"
+ become: true
+ become_user: "{{ pgsql_unix_username }}"