Make containerized galera use mysql_network everywhere
[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             tripleo::profile::pacemaker::database::mysql_bundle::bind_address:
101               str_replace:
102                 template:
103                   "%{hiera('fqdn_$NETWORK')}"
104                 params:
105                   $NETWORK: {get_param: [ServiceNetMap, MysqlNetwork]}
106           -
107             if:
108             - internal_tls_enabled
109             -
110               tripleo::profile::pacemaker::database::mysql_bundle::ca_file:
111                 get_param: InternalTLSCAFile
112             - {}
113       step_config: ""
114       # BEGIN DOCKER SETTINGS #
115       puppet_config:
116         config_volume: mysql
117         puppet_tags: file # set this even though file is the default
118         step_config:
119           list_join:
120             - "\n"
121             - - "['Mysql_datadir', 'Mysql_user', 'Mysql_database', 'Mysql_grant', 'Mysql_plugin'].each |String $val| { noop_resource($val) }"
122               - "exec {'wait-for-settle': command => '/bin/true' }"
123               - "include ::tripleo::profile::pacemaker::database::mysql_bundle"
124         config_image: {get_param: DockerMysqlConfigImage}
125       kolla_config:
126         /var/lib/kolla/config_files/mysql.json:
127           command: /usr/sbin/pacemaker_remoted
128           config_files:
129             - dest: /etc/libqb/force-filesystem-sockets
130               source: /dev/null
131               owner: root
132               perm: '0644'
133             - source: "/var/lib/kolla/config_files/src/*"
134               dest: "/"
135               merge: true
136               preserve_properties: true
137             - source: "/var/lib/kolla/config_files/src-tls/*"
138               dest: "/"
139               merge: true
140               optional: true
141               preserve_properties: true
142           permissions:
143             - path: /etc/pki/tls/certs/mysql.crt
144               owner: mysql:mysql
145               perm: '0600'
146               optional: true
147             - path: /etc/pki/tls/private/mysql.key
148               owner: mysql:mysql
149               perm: '0600'
150               optional: true
151       docker_config:
152         step_1:
153           mysql_data_ownership:
154             start_order: 0
155             detach: false
156             image: {get_param: DockerMysqlImage}
157             net: host
158             user: root
159             # Kolla does only non-recursive chown
160             command: ['chown', '-R', 'mysql:', '/var/lib/mysql']
161             volumes:
162               - /var/lib/mysql:/var/lib/mysql
163           mysql_bootstrap:
164             start_order: 1
165             detach: false
166             image: {get_param: DockerMysqlImage}
167             net: host
168             user: root
169             # Kolla bootstraps aren't idempotent, explicitly checking if bootstrap was done
170             command:
171               - 'bash'
172               - '-ecx'
173               -
174                 list_join:
175                   - "\n"
176                   - - 'if [ -e /var/lib/mysql/mysql ]; then exit 0; fi'
177                     - 'echo -e "\n[mysqld]\nwsrep_provider=none" >> /etc/my.cnf'
178                     - 'sudo -u mysql -E kolla_start'
179                     - 'mysqld_safe --skip-networking --wsrep-on=OFF &'
180                     - 'timeout ${DB_MAX_TIMEOUT} /bin/bash -c ''until mysqladmin -uroot -p"${DB_ROOT_PASSWORD}" ping 2>/dev/null; do sleep 1; done'''
181                     - 'mysql -uroot -p"${DB_ROOT_PASSWORD}" -e "CREATE USER ''clustercheck''@''localhost'' IDENTIFIED BY ''${DB_CLUSTERCHECK_PASSWORD}'';"'
182                     - 'mysql -uroot -p"${DB_ROOT_PASSWORD}" -e "GRANT PROCESS ON *.* TO ''clustercheck''@''localhost'' WITH GRANT OPTION;"'
183                     - 'timeout ${DB_MAX_TIMEOUT} mysqladmin -uroot -p"${DB_ROOT_PASSWORD}" shutdown'
184             volumes: &mysql_volumes
185               list_concat:
186                 - {get_attr: [ContainersCommon, volumes]}
187                 -
188                   - /var/lib/kolla/config_files/mysql.json:/var/lib/kolla/config_files/config.json
189                   - /var/lib/config-data/puppet-generated/mysql/:/var/lib/kolla/config_files/src:ro
190                   - /var/lib/mysql:/var/lib/mysql
191             environment:
192               - KOLLA_CONFIG_STRATEGY=COPY_ALWAYS
193               - KOLLA_BOOTSTRAP=True
194               # NOTE(mandre) skip wsrep cluster status check
195               - KOLLA_KUBERNETES=True
196               - DB_MAX_TIMEOUT=60
197               -
198                 list_join:
199                   - '='
200                   - - 'DB_CLUSTERCHECK_PASSWORD'
201                     - {get_param: MysqlClustercheckPassword}
202               -
203                 list_join:
204                   - '='
205                   - - 'DB_ROOT_PASSWORD'
206                     -
207                       yaql:
208                         expression: $.data.passwords.where($ != '').first()
209                         data:
210                           passwords:
211                             - {get_param: MysqlRootPassword}
212                             - {get_param: [DefaultPasswords, mysql_root_password]}
213           mysql_image_tag:
214             start_order: 2
215             detach: false
216             net: host
217             user: root
218             command:
219               - '/bin/bash'
220               - '-c'
221               - str_replace:
222                   template:
223                     "/usr/bin/docker tag 'MYSQL_IMAGE' 'MYSQL_IMAGE_PCMKLATEST'"
224                   params:
225                     MYSQL_IMAGE: {get_param: DockerMysqlImage}
226                     MYSQL_IMAGE_PCMKLATEST: *mysql_image_pcmklatest
227             image: {get_param: DockerMysqlImage}
228             volumes:
229               - /etc/hosts:/etc/hosts:ro
230               - /etc/localtime:/etc/localtime:ro
231               - /dev/shm:/dev/shm:rw
232               - /etc/sysconfig/docker:/etc/sysconfig/docker:ro
233               - /usr/bin:/usr/bin:ro
234               - /var/run/docker.sock:/var/run/docker.sock:rw
235         step_2:
236           mysql_init_bundle:
237             start_order: 1
238             detach: false
239             net: host
240             user: root
241             command:
242               - '/bin/bash'
243               - '-c'
244               - str_replace:
245                   template:
246                     list_join:
247                       - '; '
248                       - - "cp -a /tmp/puppet-etc/* /etc/puppet; echo '{\"step\": 2}' > /etc/puppet/hieradata/docker.json"
249                         - "FACTER_uuid=docker puppet apply --tags file,file_line,concat,augeas,TAGS -v -e 'CONFIG'"
250                   params:
251                     TAGS: 'pacemaker::resource::bundle,pacemaker::property,pacemaker::resource::ocf,pacemaker::constraint::order,pacemaker::constraint::colocation,galera_ready,mysql_database,mysql_grant,mysql_user'
252                     CONFIG: 'include ::tripleo::profile::base::pacemaker;include ::tripleo::profile::pacemaker::database::mysql_bundle'
253             image: {get_param: DockerMysqlImage}
254             volumes:
255               - /etc/hosts:/etc/hosts:ro
256               - /etc/localtime:/etc/localtime:ro
257               - /etc/puppet:/tmp/puppet-etc:ro
258               - /usr/share/openstack-puppet/modules:/usr/share/openstack-puppet/modules:ro
259               - /etc/corosync/corosync.conf:/etc/corosync/corosync.conf:ro
260               - /dev/shm:/dev/shm:rw
261               - /var/lib/mysql:/var/lib/mysql:rw
262       host_prep_tasks:
263         - name: create /var/lib/mysql
264           file:
265             path: /var/lib/mysql
266             state: directory
267       metadata_settings:
268         get_attr: [MysqlPuppetBase, role_data, metadata_settings]
269       upgrade_tasks:
270         - name: get bootstrap nodeid
271           tags: common
272           command: hiera -c /etc/puppet/hiera.yaml bootstrap_nodeid
273           register: bootstrap_node
274         - name: set is_bootstrap_node fact
275           tags: common
276           set_fact: is_bootstrap_node={{bootstrap_node.stdout|lower == ansible_hostname|lower}}
277         - name: Check cluster resource status
278           tags: step2
279           pacemaker_resource:
280             resource: galera
281             state: master
282             check_mode: true
283           ignore_errors: true
284           register: galera_res
285         - name: Disable the galera cluster resource
286           tags: step2
287           pacemaker_resource:
288             resource: galera
289             state: disable
290             wait_for_resource: true
291           register: output
292           retries: 5
293           until: output.rc == 0
294           when: is_bootstrap_node and galera_res|succeeded
295         - name: Delete the stopped galera cluster resource.
296           tags: step2
297           pacemaker_resource:
298             resource: galera
299             state: delete
300             wait_for_resource: true
301           register: output
302           retries: 5
303           until: output.rc == 0
304           when: is_bootstrap_node and galera_res|succeeded
305         - name: Disable mysql service
306           tags: step2
307           service: name=mariadb enabled=no
308         - name: Remove clustercheck service from xinetd
309           tags: step2
310           file: state=absent path=/etc/xinetd.d/galera-monitor
311         - name: Restart xinetd service after clustercheck removal
312           tags: step2
313           service: name=xinetd state=restarted