-
Notifications
You must be signed in to change notification settings - Fork 0
/
provision-edb
executable file
·232 lines (212 loc) · 9.45 KB
/
provision-edb
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
#!/usr/bin/env ansible-playbook
# (c) 2016 DataNexus Inc. All Rights Reserved.
#
# Default manifest for installing postgresql instances based on tagged role
---
- name: discovering shaw
hosts: localhost
tasks:
- ec2_remote_facts:
region: "{{ ec2_region }}"
filters:
instance-state-name: running
"tag:Application": shaw
"tag:Domain": "{{ domain }}"
"tag:Project": "{{ project }}"
"tag:Tenant": "{{ tenant }}"
register: shaw_instances
when:
- cloud == 'aws'
- name: building shaw host group
add_host: hostname="{{ item }}" groupname=shaw ansible_ssh_private_key_file="{{ key_path }}/{{ cloud }}-{{ ec2_region }}-{{ project }}-shaw-{{ domain }}-private-key.pem"
with_items: "{{ shaw_instances.instances|map(attribute='private_ip_address')|list }}"
when:
- shaw_instances.instances|length > 0
- name: fetching CA certs from shaw
hosts: shaw
gather_facts: yes
tasks:
- name: fetching CA broker keystore
fetch:
src: "/etc/tls/datanexus/ca/{{ item }}"
dest: "{{ key_path}}/{{ item }}"
flat: yes
with_items:
- ca-cert.pem
- ca-key.pem
become: true
# do the auto discovery first as we use all the nodes for master/replica configuration
- name: discovering all edb nodes
hosts: localhost
vars_files:
- vars/edb.yml
tasks:
- ec2_remote_facts:
region: "{{ ec2_region }}"
filters:
instance-state-name: running
"tag:Application": "{{ application }}"
"tag:Domain": "{{ domain }}"
"tag:Project": "{{ project }}"
"tag:Tenant": "{{ tenant }}"
register: edb_instances
when:
- cloud == 'aws'
- name: building {{ application }} host group
add_host: hostname="{{ item }}" groupname="{{ application }}" ansible_ssh_private_key_file="{{ key_path }}/{{ cloud }}-{{ ec2_region }}-{{ project }}-{{ application }}-{{ domain }}-private-key.pem"
with_items: "{{ edb_instances.instances|map(attribute='private_ip_address')|list }}"
when:
- cloud == 'aws'
- edb_instances.instances|length > 0
- name: discovering all edb_master nodes
hosts: localhost
vars_files:
- vars/edb.yml
tasks:
- ec2_remote_facts:
region: "{{ ec2_region }}"
filters:
instance-state-name: running
"tag:Application": "{{ application }}"
"tag:Domain": "{{ domain }}"
"tag:Project": "{{ project }}"
"tag:Tenant": "{{ tenant }}"
"tag:Role": master
register: postgresql_master_instances
when:
- cloud == 'aws'
- name: building {{ application }}_master host group
add_host: hostname="{{ item }}" groupname="{{ application }}_master" ansible_ssh_private_key_file="{{ key_path }}/{{ cloud }}-{{ ec2_region }}-{{ project }}-{{ application }}-{{ domain }}-private-key.pem"
with_items: "{{ postgresql_master_instances.instances|map(attribute='private_ip_address')|list }}"
when:
- cloud == 'aws'
- postgresql_master_instances.instances|length > 0
- name: discovering all edb_replica nodes
hosts: localhost
vars_files:
- vars/edb.yml
tasks:
- ec2_remote_facts:
region: "{{ ec2_region }}"
filters:
instance-state-name: running
"tag:Application": "{{ application }}"
"tag:Domain": "{{ domain }}"
"tag:Project": "{{ project }}"
"tag:Tenant": "{{ tenant }}"
"tag:Role": replica
register: postgresql_replica_instances
when:
- cloud == 'aws'
- name: building {{ application }}_replica host group
add_host: hostname="{{ item }}" groupname="{{ application }}_replica" ansible_ssh_private_key_file="{{ key_path }}/{{ cloud }}-{{ ec2_region }}-{{ project }}-{{ application }}-{{ domain }}-private-key.pem"
with_items: "{{ postgresql_replica_instances.instances|map(attribute='private_ip_address')|list }}"
when:
- cloud == 'aws'
- edb_instances.instances|length > 0
- name: install base configuration for {{ application }}
hosts: edb
vars_files:
- vars/edb.yml
- "{{ tenant_config_path }}/config/site.yml"
gather_facts: yes
roles:
- { role: configure-repo, when: ansible_distribution == 'CentOS' or ansible_distribution == 'RedHat' }
- { role: install-packages, package_list: ['{{ application }}-as{{ postgresql_major_version }}{{ postgresql_minor_version }}-server-{{ postgresql_major_version }}.{{ postgresql_minor_version }}.{{ postgresql_rev_version }}.rhel7'], when: ansible_distribution == 'CentOS' or ansible_distribution == 'RedHat' }
- { role: install-packages, package_list: "{{ postgresql_package_list }}" }
- { role: edb }
- hosts: edb_master
gather_facts: no
vars_files:
- vars/edb.yml
roles:
- { role: master-streaming }
- hosts: edb_replica
gather_facts: no
vars_files:
- vars/edb.yml
roles:
- { role: replica-streaming }
### random leftover stuff
# - name: list all instances
# debug: msg=item
# # with_items: "{{ edb_instances.instances|selectattr('state', 'equalto', 'running')|map(attribute='private_ip_address')|list }}"
# with_items: "{{ edb_instances.instances|map(attribute='private_ip_address')|list }}"
# when:
# - edb_instances.instances|length > 0
# - name: list master instances
# debug: msg=item
# with_items: "{{ postgresql_master_instances.instances|map(attribute='private_ip_address')|list }}"
# when:
# - postgresql_master_instances.instances|length > 0
#
# - name: list replica instances
# debug: msg=item
# with_items: "{{ postgresql_replica_instances.instances|map(attribute='private_ip_address')|list }}"
# when:
# - postgresql_replica_instances.instances|length > 0
# - name: creating openstack {{ application }} and {{ application }}-master host groups
# hosts: localhost
# vars_files:
# - "{{ tenant_config_path }}/blueprints/{{ tenant }}/tenant/site.yml"
# - "vars/{{ application }}.yml"
# - vars/osp.yml
# gather_facts: no
# tasks:
# - include_role:
# name: build-app-host-groups
# vars:
# domain: production
# host_group_list:
# - { name: postgresql }
# - { name: postgresql, role: master }
# - name: creating AWS {{ application }} and {{ application }}-replica host groups
# hosts: localhost
# vars_files:
# - "{{ tenant_config_path }}/blueprints/{{ tenant }}/tenant/site.yml"
# - "vars/{{ application }}.yml"
# - vars/aws.yml
# gather_facts: no
# tasks:
# - include_role:
# name: build-app-host-groups
# vars:
# domain: development
# host_group_list:
# - { name: postgresql }
# - { name: postgresql, role: master }
# - { name: postgresql, role: replica }
# when: inventory_type == 'dynamic'
#
# - name: do some debugging
# hosts: localhost
# gather_facts: no
# tasks:
# - debug: var=groups
# - debug: msg="{{ inventory_hostname }}"
# # with_items: groups
# - debug: msg="hello"
# when: "'postgresql_master' in groups and inventory_hostname in groups.postgresql_master"
# - hosts: "{{ application }}"
# vars_files:
# - vars/{{ application }}.yml
# - vars/tenant.yml
# tasks:
# - name: configuring postgresql repo on all {{ application }} nodes
# command: /usr/bin/yum -y reinstall https://download.postgresql.org/pub/repos/yum/{{ postgresql_major_version }}.{{ postgresql_minor_version }}/redhat/rhel-7-x86_64/pgdg-{{ ansible_distribution|lower }}{{ postgresql_major_version }}{{ postgresql_minor_version }}-{{ postgresql_major_version }}.{{ postgresql_minor_version }}-3.noarch.rpm
# become: yes
#
# - hosts: "{{ application }}"
# vars_files:
# - vars/{{ application }}.yml
# gather_facts: yes
# roles:
# # - { role: common-roles/add-package-repo, package_name: "pgdg96", repo_name: "PostgreSQL 9.6", repo_url: "https://download.postgresql.org/pub/repos/yum/srpms/9.6/redhat/rhel-$releasever-$basearch", repo_key_url: "file:///etc/pki/rpm-gpg/RPM-GPG-KEY-PGDG-96", when: proxy_env is defined }
# # - { role: install-packages, package_list: ['epel-release-7-9', 'https://download.postgresql.org/pub/repos/yum/{{ postgresql_major_version }}.{{ postgresql_minor_version }}/redhat/rhel-7-x86_64/pgdg-centos{{ postgresql_major_version }}{{ postgresql_minor_version }}-{{ postgresql_major_version }}.{{ postgresql_minor_version }}-3.noarch.rpm'] }
# - { role: install-packages, package_list: ['epel-release-7-9'], when: ansible_distribution == 'CentOS' }
# - { role: install-packages, package_list: "{{ postgresql_package_list }}" }
# - { role: get-iface-addr, iface_name: "{{ postgresql_interface }}" }
# - { role: dn-postgresql, postgresql_addr: "{{ iface_addr }}" }
#
# - { role: common-roles/add-package-repo, package_name: "pgdg96", repo_name: "PostgreSQL 9.6", repo_url: "https://download.postgresql.org/pub/repos/yum/srpms/9.6/redhat/rhel-$releasever-$basearch", repo_key_url: "file:///etc/pki/rpm-gpg/RPM-GPG-KEY-PGDG-96", when: proxy_env is defined }
# - { role: install-packages, package_list: ['epel-release-7-9', 'https://download.postgresql.org/pub/repos/yum/{{ postgresql_major_version }}.{{ postgresql_minor_version }}/redhat/rhel-7-x86_64/pgdg-centos{{ postgresql_major_version }}{{ postgresql_minor_version }}-{{ postgresql_major_version }}.{{ postgresql_minor_version }}-3.noarch.rpm'] }