Adds pacemaker update_tasks for Pike minor update workflow
[apex-tripleo-heat-templates.git] / docker / services / pacemaker / database / mysql.yaml
1 heat_template_version: pike
2
3 description: >
4   MySQL service deployment with pacemaker bundle
5
6 parameters:
7   DockerMysqlImage:
8     description: image
9     type: string
10   DockerMysqlConfigImage:
11     description: The container image to use for the mysql config_volume
12     type: string
13   EndpointMap:
14     default: {}
15     description: Mapping of service endpoint -> protocol. Typically set
16                  via parameter_defaults in the resource registry.
17     type: json
18   ServiceData:
19     default: {}
20     description: Dictionary packing service data
21     type: json
22   ServiceNetMap:
23     default: {}
24     description: Mapping of service_name -> network name. Typically set
25                  via parameter_defaults in the resource registry.  This
26                  mapping overrides those in ServiceNetMapDefaults.
27     type: json
28   DefaultPasswords:
29     default: {}
30     type: json
31   MysqlRootPassword:
32     type: string
33     hidden: true
34     default: ''
35   MysqlClustercheckPassword:
36     type: string
37     hidden: true
38   RoleName:
39     default: ''
40     description: Role name on which the service is applied
41     type: string
42   RoleParameters:
43     default: {}
44     description: Parameters specific to the role
45     type: json
46   EnableInternalTLS:
47     type: boolean
48     default: false
49   InternalTLSCAFile:
50     default: '/etc/ipa/ca.crt'
51     type: string
52     description: Specifies the default CA cert to use if TLS is used for
53                  services in the internal network.
54
55 resources:
56
57   ContainersCommon:
58     type: ../../containers-common.yaml
59
60   MysqlPuppetBase:
61     type: ../../../../puppet/services/pacemaker/database/mysql.yaml
62     properties:
63       EndpointMap: {get_param: EndpointMap}
64       ServiceData: {get_param: ServiceData}
65       ServiceNetMap: {get_param: ServiceNetMap}
66       DefaultPasswords: {get_param: DefaultPasswords}
67       RoleName: {get_param: RoleName}
68       RoleParameters: {get_param: RoleParameters}
69
70 conditions:
71
72   internal_tls_enabled: {equals: [{get_param: EnableInternalTLS}, true]}
73
74 outputs:
75   role_data:
76     description: Containerized service MySQL using composable services.
77     value:
78       service_name: {get_attr: [MysqlPuppetBase, role_data, service_name]}
79       config_settings:
80         map_merge:
81           - {get_attr: [MysqlPuppetBase, role_data, config_settings]}
82           - tripleo::profile::pacemaker::database::mysql_bundle::mysql_docker_image: &mysql_image_pcmklatest
83               list_join:
84                 - ':'
85                 - - yaql:
86                       data: {get_param: DockerMysqlImage}
87                       expression: $.data.rightSplit(separator => ":", maxSplits => 1)[0]
88                   - 'pcmklatest'
89             tripleo::profile::pacemaker::database::mysql_bundle::control_port: 3123
90             tripleo.mysql.firewall_rules:
91               '104 mysql galera-bundle':
92                 dport:
93                   - 873
94                   - 3123
95                   - 3306
96                   - 4444
97                   - 4567
98                   - 4568
99                   - 9200
100           -
101             if:
102             - internal_tls_enabled
103             -
104               tripleo::profile::pacemaker::database::mysql_bundle::ca_file:
105                 get_param: InternalTLSCAFile
106             - {}
107       logging_source: {get_attr: [MysqlPuppetBase, role_data, logging_source]}
108       logging_groups: {get_attr: [MysqlPuppetBase, role_data, logging_groups]}
109       step_config: ""
110       # BEGIN DOCKER SETTINGS #
111       puppet_config:
112         config_volume: mysql
113         puppet_tags: file # set this even though file is the default
114         step_config:
115           list_join:
116             - "\n"
117             - - "['Mysql_datadir', 'Mysql_user', 'Mysql_database', 'Mysql_grant', 'Mysql_plugin'].each |String $val| { noop_resource($val) }"
118               - "exec {'wait-for-settle': command => '/bin/true' }"
119               - "include ::tripleo::profile::pacemaker::database::mysql_bundle"
120         config_image: {get_param: DockerMysqlConfigImage}
121       kolla_config:
122         /var/lib/kolla/config_files/mysql.json:
123           command: /usr/sbin/pacemaker_remoted
124           config_files:
125             - dest: /etc/libqb/force-filesystem-sockets
126               source: /dev/null
127               owner: root
128               perm: '0644'
129             - source: "/var/lib/kolla/config_files/src/*"
130               dest: "/"
131               merge: true
132               preserve_properties: true
133             - source: "/var/lib/kolla/config_files/src-tls/*"
134               dest: "/"
135               merge: true
136               optional: true
137               preserve_properties: true
138           permissions:
139             - path: /etc/pki/tls/certs/mysql.crt
140               owner: mysql:mysql
141               perm: '0600'
142               optional: true
143             - path: /etc/pki/tls/private/mysql.key
144               owner: mysql:mysql
145               perm: '0600'
146               optional: true
147       docker_config:
148         step_1:
149           mysql_data_ownership:
150             start_order: 0
151             detach: false
152             image: {get_param: DockerMysqlImage}
153             net: host
154             user: root
155             # Kolla does only non-recursive chown
156             command: ['chown', '-R', 'mysql:', '/var/lib/mysql']
157             volumes:
158               - /var/lib/mysql:/var/lib/mysql
159           mysql_bootstrap:
160             start_order: 1
161             detach: false
162             image: {get_param: DockerMysqlImage}
163             net: host
164             user: root
165             # Kolla bootstraps aren't idempotent, explicitly checking if bootstrap was done
166             command:
167               - 'bash'
168               - '-ecx'
169               -
170                 list_join:
171                   - "\n"
172                   - - 'if [ -e /var/lib/mysql/mysql ]; then exit 0; fi'
173                     - 'echo -e "\n[mysqld]\nwsrep_provider=none" >> /etc/my.cnf'
174                     - 'sudo -u mysql -E kolla_start'
175                     - 'mysqld_safe --skip-networking --wsrep-on=OFF &'
176                     - 'timeout ${DB_MAX_TIMEOUT} /bin/bash -c ''until mysqladmin -uroot -p"${DB_ROOT_PASSWORD}" ping 2>/dev/null; do sleep 1; done'''
177                     - 'mysql -uroot -p"${DB_ROOT_PASSWORD}" -e "CREATE USER ''clustercheck''@''localhost'' IDENTIFIED BY ''${DB_CLUSTERCHECK_PASSWORD}'';"'
178                     - 'mysql -uroot -p"${DB_ROOT_PASSWORD}" -e "GRANT PROCESS ON *.* TO ''clustercheck''@''localhost'' WITH GRANT OPTION;"'
179                     - 'timeout ${DB_MAX_TIMEOUT} mysqladmin -uroot -p"${DB_ROOT_PASSWORD}" shutdown'
180             volumes: &mysql_volumes
181               list_concat:
182                 - {get_attr: [ContainersCommon, volumes]}
183                 -
184                   - /var/lib/kolla/config_files/mysql.json:/var/lib/kolla/config_files/config.json
185                   - /var/lib/config-data/puppet-generated/mysql/:/var/lib/kolla/config_files/src:ro
186                   - /var/lib/mysql:/var/lib/mysql
187             environment:
188               - KOLLA_CONFIG_STRATEGY=COPY_ALWAYS
189               - KOLLA_BOOTSTRAP=True
190               # NOTE(mandre) skip wsrep cluster status check
191               - KOLLA_KUBERNETES=True
192               - DB_MAX_TIMEOUT=60
193               -
194                 list_join:
195                   - '='
196                   - - 'DB_CLUSTERCHECK_PASSWORD'
197                     - {get_param: MysqlClustercheckPassword}
198               -
199                 list_join:
200                   - '='
201                   - - 'DB_ROOT_PASSWORD'
202                     -
203                       yaql:
204                         expression: $.data.passwords.where($ != '').first()
205                         data:
206                           passwords:
207                             - {get_param: MysqlRootPassword}
208                             - {get_param: [DefaultPasswords, mysql_root_password]}
209           mysql_image_tag:
210             start_order: 2
211             detach: false
212             net: host
213             user: root
214             command:
215               - '/bin/bash'
216               - '-c'
217               - str_replace:
218                   template:
219                     "/usr/bin/docker tag 'MYSQL_IMAGE' 'MYSQL_IMAGE_PCMKLATEST'"
220                   params:
221                     MYSQL_IMAGE: {get_param: DockerMysqlImage}
222                     MYSQL_IMAGE_PCMKLATEST: *mysql_image_pcmklatest
223             image: {get_param: DockerMysqlImage}
224             volumes:
225               - /etc/hosts:/etc/hosts:ro
226               - /etc/localtime:/etc/localtime:ro
227               - /dev/shm:/dev/shm:rw
228               - /etc/sysconfig/docker:/etc/sysconfig/docker:ro
229               - /usr/bin:/usr/bin:ro
230               - /var/run/docker.sock:/var/run/docker.sock:rw
231         step_2:
232           mysql_init_bundle:
233             start_order: 1
234             detach: false
235             net: host
236             user: root
237             command:
238               - '/bin/bash'
239               - '-c'
240               - str_replace:
241                   template:
242                     list_join:
243                       - '; '
244                       - - "cp -a /tmp/puppet-etc/* /etc/puppet; echo '{\"step\": 2}' > /etc/puppet/hieradata/docker.json"
245                         - "FACTER_uuid=docker puppet apply --tags file,file_line,concat,augeas,TAGS -v -e 'CONFIG'"
246                   params:
247                     TAGS: 'pacemaker::resource::bundle,pacemaker::property,pacemaker::resource::ocf,pacemaker::constraint::order,pacemaker::constraint::colocation,galera_ready,mysql_database,mysql_grant,mysql_user'
248                     CONFIG: 'include ::tripleo::profile::base::pacemaker;include ::tripleo::profile::pacemaker::database::mysql_bundle'
249             image: {get_param: DockerMysqlImage}
250             volumes:
251               - /etc/hosts:/etc/hosts:ro
252               - /etc/localtime:/etc/localtime:ro
253               - /etc/puppet:/tmp/puppet-etc:ro
254               - /usr/share/openstack-puppet/modules:/usr/share/openstack-puppet/modules:ro
255               - /etc/corosync/corosync.conf:/etc/corosync/corosync.conf:ro
256               - /dev/shm:/dev/shm:rw
257               - /var/lib/mysql:/var/lib/mysql:rw
258       host_prep_tasks:
259         - name: create /var/lib/mysql
260           file:
261             path: /var/lib/mysql
262             state: directory
263       metadata_settings:
264         get_attr: [MysqlPuppetBase, role_data, metadata_settings]
265       upgrade_tasks:
266         - name: get bootstrap nodeid
267           tags: common
268           command: hiera -c /etc/puppet/hiera.yaml bootstrap_nodeid
269           register: bootstrap_node
270         - name: set is_bootstrap_node fact
271           tags: common
272           set_fact: is_bootstrap_node={{bootstrap_node.stdout|lower == ansible_hostname|lower}}
273         - name: Check cluster resource status
274           tags: step2
275           pacemaker_resource:
276             resource: galera
277             state: master
278             check_mode: true
279           ignore_errors: true
280           register: galera_res
281         - name: Disable the galera cluster resource
282           tags: step2
283           pacemaker_resource:
284             resource: galera
285             state: disable
286             wait_for_resource: true
287           register: output
288           retries: 5
289           until: output.rc == 0
290           when: is_bootstrap_node and galera_res|succeeded
291         - name: Delete the stopped galera cluster resource.
292           tags: step2
293           pacemaker_resource:
294             resource: galera
295             state: delete
296             wait_for_resource: true
297           register: output
298           retries: 5
299           until: output.rc == 0
300           when: is_bootstrap_node and galera_res|succeeded
301         - name: Disable mysql service
302           tags: step2
303           service: name=mariadb enabled=no
304         - name: Remove clustercheck service from xinetd
305           tags: step2
306           file: state=absent path=/etc/xinetd.d/galera-monitor
307         - name: Restart xinetd service after clustercheck removal
308           tags: step2
309           service: name=xinetd state=restarted
310       update_tasks:
311         - name: Get docker Mariadb image
312           set_fact:
313             docker_image: {get_param: DockerMysqlImage}
314             docker_image_latest: *mysql_image_pcmklatest
315           when: step == '2'
316         - name: Get previous Mariadb image id
317           shell: "docker images | awk '/mariadb.* pcmklatest/{print $3}'"
318           register: mariadb_image_id
319         - block:
320             - name: Get a list of container using Mariadb image
321               shell: "docker ps -q -f 'ancestor={{mariadb_image_id.stdout}}'"
322               register: mariadb_containers_to_destroy
323             # It will be recreated with the delpoy step.
324             - name: Remove any container using the same Mariadb image
325               shell: "docker rm -fv {{item}}"
326               with_items: "{{ mariadb_containers_to_destroy.stdout_lines }}"
327             - name: Remove previous Mariadb images
328               shell: "docker rmi -f {{mariadb_image_id.stdout}}"
329           when:
330             - step == '2'
331             - mariadb_image_id.stdout != ''
332         - name: Pull latest Mariadb images
333           command: "docker pull {{docker_image}}"
334           when: step == "2"
335         - name: Retag pcmklatest to latest Mariadb image
336           shell: "docker tag {{docker_image}} {{docker_image_latest}}"
337           when: step == "2"
338         # Got to check that pacemaker_is_active is working fine with bundle.
339         # TODO: pacemaker_is_active resource doesn't support bundle.