Merge "Enable TLS configuration for containerized Galera"
[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 {get_param: DockerMysqlImage}
83             tripleo::profile::pacemaker::database::mysql_bundle::control_port: 3123
84             tripleo.mysql.firewall_rules:
85               '104 mysql galera-bundle':
86                 dport:
87                   - 873
88                   - 3123
89                   - 3306
90                   - 4444
91                   - 4567
92                   - 4568
93                   - 9200
94           -
95             if:
96             - internal_tls_enabled
97             -
98               tripleo::profile::pacemaker::database::mysql_bundle::ca_file:
99                 get_param: InternalTLSCAFile
100             - {}
101       step_config: ""
102       # BEGIN DOCKER SETTINGS #
103       puppet_config:
104         config_volume: mysql
105         puppet_tags: file # set this even though file is the default
106         step_config:
107           list_join:
108             - "\n"
109             - - "['Mysql_datadir', 'Mysql_user', 'Mysql_database', 'Mysql_grant', 'Mysql_plugin'].each |String $val| { noop_resource($val) }"
110               - "exec {'wait-for-settle': command => '/bin/true' }"
111               - "include ::tripleo::profile::pacemaker::database::mysql_bundle"
112         config_image: {get_param: DockerMysqlConfigImage}
113       kolla_config:
114         /var/lib/kolla/config_files/mysql.json:
115           command: /usr/sbin/pacemaker_remoted
116           config_files:
117             - dest: /etc/libqb/force-filesystem-sockets
118               source: /dev/null
119               owner: root
120               perm: '0644'
121             - source: "/var/lib/kolla/config_files/src/*"
122               dest: "/"
123               merge: true
124               preserve_properties: true
125             - source: "/var/lib/kolla/config_files/src-tls/*"
126               dest: "/"
127               merge: true
128               optional: true
129               preserve_properties: true
130           permissions:
131             - path: /etc/pki/tls/certs/mysql.crt
132               owner: mysql:mysql
133               perm: '0600'
134               optional: true
135             - path: /etc/pki/tls/private/mysql.key
136               owner: mysql:mysql
137               perm: '0600'
138               optional: true
139       docker_config:
140         step_1:
141           mysql_data_ownership:
142             start_order: 0
143             detach: false
144             image: *mysql_image
145             net: host
146             user: root
147             # Kolla does only non-recursive chown
148             command: ['chown', '-R', 'mysql:', '/var/lib/mysql']
149             volumes:
150               - /var/lib/mysql:/var/lib/mysql
151           mysql_bootstrap:
152             start_order: 1
153             detach: false
154             image: *mysql_image
155             net: host
156             # Kolla bootstraps aren't idempotent, explicitly checking if bootstrap was done
157             command:
158               - 'bash'
159               - '-ec'
160               -
161                 list_join:
162                   - "\n"
163                   - - 'if [ -e /var/lib/mysql/mysql ]; then exit 0; fi'
164                     - 'kolla_start'
165                     - 'mysqld_safe --skip-networking --wsrep-on=OFF &'
166                     - 'timeout ${DB_MAX_TIMEOUT} /bin/bash -c ''until mysqladmin -uroot -p"${DB_ROOT_PASSWORD}" ping 2>/dev/null; do sleep 1; done'''
167                     - 'mysql -uroot -p"${DB_ROOT_PASSWORD}" -e "CREATE USER ''clustercheck''@''localhost'' IDENTIFIED BY ''${DB_CLUSTERCHECK_PASSWORD}'';"'
168                     - 'mysql -uroot -p"${DB_ROOT_PASSWORD}" -e "GRANT PROCESS ON *.* TO ''clustercheck''@''localhost'' WITH GRANT OPTION;"'
169                     - 'timeout ${DB_MAX_TIMEOUT} mysqladmin -uroot -p"${DB_ROOT_PASSWORD}" shutdown'
170             volumes: &mysql_volumes
171               list_concat:
172                 - {get_attr: [ContainersCommon, volumes]}
173                 -
174                   - /var/lib/kolla/config_files/mysql.json:/var/lib/kolla/config_files/config.json
175                   - /var/lib/config-data/puppet-generated/mysql/:/var/lib/kolla/config_files/src:ro
176                   - /var/lib/mysql:/var/lib/mysql
177             environment:
178               - KOLLA_CONFIG_STRATEGY=COPY_ALWAYS
179               - KOLLA_BOOTSTRAP=True
180               # NOTE(mandre) skip wsrep cluster status check
181               - KOLLA_KUBERNETES=True
182               - DB_MAX_TIMEOUT=60
183               -
184                 list_join:
185                   - '='
186                   - - 'DB_CLUSTERCHECK_PASSWORD'
187                     - {get_param: MysqlClustercheckPassword}
188               -
189                 list_join:
190                   - '='
191                   - - 'DB_ROOT_PASSWORD'
192                     -
193                       yaql:
194                         expression: $.data.passwords.where($ != '').first()
195                         data:
196                           passwords:
197                             - {get_param: MysqlRootPassword}
198                             - {get_param: [DefaultPasswords, mysql_root_password]}
199         step_2:
200           mysql_init_bundle:
201             start_order: 1
202             detach: false
203             net: host
204             user: root
205             command:
206               - '/bin/bash'
207               - '-c'
208               - str_replace:
209                   template:
210                     list_join:
211                       - '; '
212                       - - "cp -a /tmp/puppet-etc/* /etc/puppet; echo '{\"step\": 2}' > /etc/puppet/hieradata/docker.json"
213                         - "FACTER_uuid=docker puppet apply --tags file,file_line,concat,augeas,TAGS -v -e 'CONFIG'"
214                   params:
215                     TAGS: 'pacemaker::resource::bundle,pacemaker::property,pacemaker::resource::ocf,pacemaker::constraint::order,pacemaker::constraint::colocation,galera_ready,mysql_database,mysql_grant,mysql_user'
216                     CONFIG: 'include ::tripleo::profile::base::pacemaker;include ::tripleo::profile::pacemaker::database::mysql_bundle'
217             image: *mysql_image
218             volumes:
219               - /etc/hosts:/etc/hosts:ro
220               - /etc/localtime:/etc/localtime:ro
221               - /etc/puppet:/tmp/puppet-etc:ro
222               - /usr/share/openstack-puppet/modules:/usr/share/openstack-puppet/modules:ro
223               - /etc/corosync/corosync.conf:/etc/corosync/corosync.conf:ro
224               - /dev/shm:/dev/shm:rw
225               - /var/lib/mysql:/var/lib/mysql:rw
226       host_prep_tasks:
227         - name: create /var/lib/mysql
228           file:
229             path: /var/lib/mysql
230             state: directory
231       metadata_settings:
232         get_attr: [MysqlPuppetBase, role_data, metadata_settings]
233       upgrade_tasks:
234         - name: get bootstrap nodeid
235           tags: common
236           command: hiera -c /etc/puppet/hiera.yaml bootstrap_nodeid
237           register: bootstrap_node
238         - name: set is_bootstrap_node fact
239           tags: common
240           set_fact: is_bootstrap_node={{bootstrap_node.stdout|lower == ansible_hostname|lower}}
241         - name: Disable the galera cluster resource
242           tags: step2
243           pacemaker_resource:
244             resource: galera
245             state: disable
246             wait_for_resource: true
247           when: is_bootstrap_node
248         - name: Delete the stopped galera cluster resource.
249           tags: step2
250           pacemaker_resource:
251             resource: galera
252             state: delete
253             wait_for_resource: true
254           when: is_bootstrap_node
255         - name: Disable mysql service
256           tags: step2
257           service: name=mariadb enabled=no