Initial commit of PostgreSQL ansible role
Change-Id: Ieb82fed65ac8957058c4269182e1ea06f5bb87ee
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 }}"