forked from quay/quay-ansible
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup-container-postgres.yml
64 lines (63 loc) · 1.89 KB
/
setup-container-postgres.yml
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
- name: Setup Postgres Container
hosts: postgres
gather_facts: no
any_errors_fatal: yes
tags:
- postgres
vars:
postgres_data_dir: /var/data/postgres
tasks:
- when: postgres_runtime_user is defined
block:
- name: Get Postgres User UID
shell: "getent passwd {{ postgres_runtime_user }} | cut -d ':' -f 3 || false"
changed_when: false
register: postgres_runtime_uid_out
- name: Setup user for Postgres
when: "postgres_runtime_uid_out.stdout | default('') == ''"
user:
name: "{{ postgres_runtime_user }}"
system: yes
home: /dev/null
shell: /bin/false
create_home: no
- name: Get Postgres User UID
shell: "getent passwd {{ postgres_runtime_user }} | cut -d ':' -f 3 || false"
changed_when: false
register: postgres_runtime_uid_out
- name: Set Postgres User UID Fact
set_fact:
postgres_runtime_uid: "{{ postgres_runtime_uid_out.stdout }}"
- name: Create Postgres Container Directories
tags:
- folders
file:
path: "{{ postgres_data_dir }}/{{ item }}"
state: directory
owner: "{{ postgres_runtime_user | default(omit) }}"
group: "{{ postgres_runtime_user | default(omit) }}"
mode: 0755
with_items:
- ''
- data
- name: Start Postgres Container
docker_container:
name: postgres
user: "{{ postgres_runtime_uid | default(omit) }}"
restart: yes
restart_policy: unless-stopped
image: registry.redhat.io/rhscl/postgresql-96-rhel7:1
published_ports:
- 5432:5432
env:
POSTGRESQL_ADMIN_PASSWORD: "{{ quay_db_admin_password }}"
state: started
volumes:
- "{{ /var/data/postgres }}/data:/var/lib/pgsql/data:Z"
- name: Wait for Postgres Container
delegate_to: localhost
wait_for:
host: "{{ inventory_hostname }}"
port: "5432"
delay: 5
timeout: 60