diff options
Diffstat (limited to 'tasks/postgres-cluster.yml')
-rw-r--r-- | tasks/postgres-cluster.yml | 85 |
1 files changed, 85 insertions, 0 deletions
diff --git a/tasks/postgres-cluster.yml b/tasks/postgres-cluster.yml new file mode 100644 index 0000000..83958d2 --- /dev/null +++ b/tasks/postgres-cluster.yml | |||
@@ -0,0 +1,85 @@ | |||
1 | - name: Install postgresql version {{ postgres_version }} | ||
2 | apt: name=postgresql-{{ postgres_version }} | ||
3 | when: ansible_distribution_release != 'NA' | ||
4 | |||
5 | - name: Install pg_repack version {{ postgres_version }} | ||
6 | apt: name=postgresql-{{ postgres_version }}-repack | ||
7 | when: | ||
8 | - ansible_distribution_release != 'NA' | ||
9 | - postgres_version in ['9.3', '9.4', '9.5', '9.6', '10'] | ||
10 | |||
11 | - name: Set initdb options | ||
12 | set_fact: postgres_initdb_option="{% if postgres_checksums %}--data-checksums{% endif %}" | ||
13 | |||
14 | - name: Create postgres cluster {{ postgres_version }}/{{ postgres_cluster_name }} if needed | ||
15 | command: /usr/bin/pg_createcluster {{ postgres_version }} {{ postgres_cluster_name }} -- {{ postgres_initdb_option }} | ||
16 | args: | ||
17 | creates: /var/lib/postgresql/{{ postgres_version }}/{{ postgres_cluster_name }}/ | ||
18 | |||
19 | - name: Check postgres server key | ||
20 | stat: path=/var/lib/postgresql/{{ postgres_version }}/{{ postgres_cluster_name }}/server.key | ||
21 | register: server_key | ||
22 | |||
23 | - name: Copy snakeoil key in postgres dir | ||
24 | copy: | ||
25 | src=/etc/ssl/private/ssl-cert-snakeoil.key | ||
26 | dest=/var/lib/postgresql/{{ postgres_version }}/{{ postgres_cluster_name }}/server.key | ||
27 | remote_src=true | ||
28 | owner=postgres | ||
29 | group=postgres | ||
30 | mode="0600" | ||
31 | when: not server_key.stat.exists or server_key.stat.islnk | ||
32 | |||
33 | - name: Check postgres server certificate | ||
34 | stat: path=/var/lib/postgresql/{{ postgres_version }}/{{ postgres_cluster_name }}/server.crt | ||
35 | register: server_crt | ||
36 | |||
37 | - name: Copy snakeoil certificate in postgres dir | ||
38 | copy: | ||
39 | src=/etc/ssl/certs/ssl-cert-snakeoil.pem | ||
40 | dest=/var/lib/postgresql/{{ postgres_version }}/{{ postgres_cluster_name }}/server.crt | ||
41 | remote_src=true | ||
42 | owner=postgres | ||
43 | group=postgres | ||
44 | mode="0644" | ||
45 | when: not server_crt.stat.exists or server_crt.stat.islnk | ||
46 | |||
47 | - name: Add standby clone from barman script | ||
48 | include: postgres-standby-barman.yml | ||
49 | when: postgres_barman_server is defined | ||
50 | |||
51 | - name: Determine SSD or rotational disks | ||
52 | raw: 'lsblk --noheadings --nodeps --raw --output=rota | grep -q 1' | ||
53 | check_mode: no | ||
54 | ignore_errors: yes | ||
55 | register: rotational_disk | ||
56 | |||
57 | - name: Set specific random page cost for SSDs | ||
58 | set_fact: | ||
59 | postgres_specific_random_page_cost: "1.0" | ||
60 | when: | ||
61 | - rotational_disk.failed is defined | ||
62 | - rotational_disk.failed | ||
63 | |||
64 | - name: Upload postgresql.conf | ||
65 | template: src=postgresql.{{ postgres_version }}.conf.j2 dest=/etc/postgresql/{{ postgres_version }}/{{ postgres_cluster_name }}/postgresql.conf | ||
66 | |||
67 | - name: Upload pg_hba.conf | ||
68 | template: src=pg_hba.conf.j2 dest=/etc/postgresql/{{ postgres_version }}/{{ postgres_cluster_name }}/pg_hba.conf | ||
69 | |||
70 | - name: Upload recovery.conf | ||
71 | template: src=recovery.conf.j2 dest=/var/lib/postgresql/{{ postgres_version }}/{{ postgres_cluster_name }}/recovery.conf owner=postgres group=postgres mode=0600 | ||
72 | when: postgres_primary | ||
73 | no_log: True | ||
74 | |||
75 | - name: Create log file | ||
76 | file: | ||
77 | path={{ postgres_log_dir }}/postgresql-{{ postgres_version }}-{{ postgres_cluster_name }}.log | ||
78 | state=touch | ||
79 | owner=postgres | ||
80 | group=adm | ||
81 | when: postgres_log_dir is defined and postgres_log_dir | ||
82 | |||
83 | - name: Create log symlink for pg_lsclusters | ||
84 | file: dest=/etc/postgresql/{{ postgres_version }}/{{ postgres_cluster_name }}/log src={{ postgres_log_dir }}/postgresql-{{ postgres_version }}-{{ postgres_cluster_name }}.log state=link | ||
85 | when: postgres_log_dir is defined and postgres_log_dir | ||