- name: Gather OS Specific Variables
  include_vars: "{{ item }}"
  with_first_found:
    - "../vars/{{ ansible_distribution }}-{{ ansible_distribution_version }}.yml"
    - "../vars/{{ ansible_distribution }}.yml"
    - "../vars/{{ ansible_os_family }}.yml"
  tags:
    - pg_instance

- name: ensure pg running
  service:
    name: "{{postgres_service}}"
    state: started
    enabled: yes

- name: create pg DB user "{{db_user}}"
  postgresql_user: name={{ db_user }} password={{ db_password }} state=present encrypted=True
  become_user: root
  become: yes
  tags:
    - pg_instance

- name: create pg DB "{{ db_name }}"
  postgresql_db: name={{ db_name }} owner={{ db_user }} state=present
  become_user: postgres
  become: yes
  tags:
    - pg_instance

- name: enable extensions for "{{ db_name }}"
  postgresql_ext:
    name: "{{ item }}"
    db: "{{ db_name }}"
  with_items: "{{ extensions }}"
  become_user: postgres
  become: yes
  tags:
    - pg_instance

- name: Gather OS Specific Variables
  include_vars: "{{ item }}"
  with_first_found:
    - "../vars/{{ ansible_distribution }}-{{ ansible_distribution_version }}.yml"
    - "../vars/{{ ansible_distribution }}.yml"
    - "../vars/{{ ansible_os_family }}.yml"
  tags:
    - pg_instance

- name: ensure pg running
  service:
    name: "{{postgres_service}}"
    state: started
    enabled: yes

- name: create pg DB user "{{db_user}}"
  postgresql_user: name={{ db_user }} password={{ db_password }} state=present encrypted=True
  become_user: postgres
  become: yes
  tags:
    - pg_instance

- name: create pg DB "{{ db_name }}"
  postgresql_db: name={{ db_name }} owner={{ db_user }} state=present
  become_user: postgres
  become: yes
  tags:
    - pg_instance

- name: enable extensions for "{{ db_name }}"
  postgresql_ext:
    name: "{{ item }}"
    db: "{{ db_name }}"
  with_items: "{{ extensions }}"
  become_user: postgres
  become: yes
  tags:
    - pg_instance

Revert "Need to be root user to create postgres user"
Revert "Need to be root user to create postgres user"

This reverts commit 40f57967e2e7ef2328355e81c8eb1be7f1fa1193.
