aboutsummaryrefslogtreecommitdiffhomepage
path: root/tasks/postgres-user.yml
blob: 000ea80c3f13f7e256bb379ce65b604d7d46f3bc (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
- name: Test if the PostgreSQL server is up
  become: true
  become_user: postgres
  become_method: "{{ postgres_become_method }}"
  command: psql --port={{ postgres_port }} --command='select NOW()'
  register: postgres_up
  ignore_errors: yes
  check_mode: no
  changed_when: false

- name: "Install required packages for 'postgres_user' ansible module"
  apt:
    name:
      - libpq-dev
      - python-psycopg2

- name: Create PostgreSQL user
  become: true
  become_user: postgres
  become_method: "{{ postgres_become_method }}"
  postgresql_user:
    port:             "{{ postgres_port }}"
    name:             "{{ postgres_username }}"
    password:         "{{ postgres_password }}"
    encrypted:        true
    role_attr_flags:  "{{ postgres_permissions }}"
  when:
    - postgres_up.rc == 0