Merge "Keep dynamic network creation backward compatible."
[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
47 resources:
48
49   ContainersCommon:
50     type: ../../containers-common.yaml
51
52   MysqlPuppetBase:
53     type: ../../../../puppet/services/pacemaker/database/mysql.yaml
54     properties:
55       EndpointMap: {get_param: EndpointMap}
56       ServiceData: {get_param: ServiceData}
57       ServiceNetMap: {get_param: ServiceNetMap}
58       DefaultPasswords: {get_param: DefaultPasswords}
59       RoleName: {get_param: RoleName}
60       RoleParameters: {get_param: RoleParameters}
61
62 outputs:
63   role_data:
64     description: Containerized service MySQL using composable services.
65     value:
66       service_name: {get_attr: [MysqlPuppetBase, role_data, service_name]}
67       config_settings:
68         map_merge:
69           - {get_attr: [MysqlPuppetBase, role_data, config_settings]}
70           - tripleo::profile::pacemaker::database::mysql_bundle::mysql_docker_image: &mysql_image {get_param: DockerMysqlImage}
71             tripleo::profile::pacemaker::database::mysql_bundle::control_port: 3123
72             tripleo.mysql.firewall_rules:
73               '104 mysql galera-bundle':
74                 dport:
75                   - 873
76                   - 3123
77                   - 3306
78                   - 4444
79                   - 4567
80                   - 4568
81                   - 9200
82       step_config: ""
83       # BEGIN DOCKER SETTINGS #
84       puppet_config:
85         config_volume: mysql
86         puppet_tags: file # set this even though file is the default
87         step_config:
88           list_join:
89             - "\n"
90             - - "['Mysql_datadir', 'Mysql_user', 'Mysql_database', 'Mysql_grant', 'Mysql_plugin'].each |String $val| { noop_resource($val) }"
91               - "exec {'wait-for-settle': command => '/bin/true' }"
92               - "include ::tripleo::profile::pacemaker::database::mysql_bundle"
93         config_image: {get_param: DockerMysqlConfigImage}
94       kolla_config:
95         /var/lib/kolla/config_files/mysql.json:
96           command: /usr/sbin/pacemaker_remoted
97           config_files:
98             - dest: /etc/libqb/force-filesystem-sockets
99               source: /dev/null
100               owner: root
101               perm: '0644'
102             - source: "/var/lib/kolla/config_files/src/*"
103               dest: "/"
104               merge: true
105               preserve_properties: true
106       docker_config:
107         step_1:
108           mysql_data_ownership:
109             start_order: 0
110             detach: false
111             image: *mysql_image
112             net: host
113             user: root
114             # Kolla does only non-recursive chown
115             command: ['chown', '-R', 'mysql:', '/var/lib/mysql']
116             volumes:
117               - /var/lib/mysql:/var/lib/mysql
118           mysql_bootstrap:
119             start_order: 1
120             detach: false
121             image: *mysql_image
122             net: host
123             # Kolla bootstraps aren't idempotent, explicitly checking if bootstrap was done
124             command:
125               - 'bash'
126               - '-ec'
127               -
128                 list_join:
129                   - "\n"
130                   - - 'if [ -e /var/lib/mysql/mysql ]; then exit 0; fi'
131                     - 'kolla_start'
132                     - 'mysqld_safe --skip-networking --wsrep-on=OFF &'
133                     - 'timeout ${DB_MAX_TIMEOUT} /bin/bash -c ''until mysqladmin -uroot -p"${DB_ROOT_PASSWORD}" ping 2>/dev/null; do sleep 1; done'''
134                     - 'mysql -uroot -p"${DB_ROOT_PASSWORD}" -e "CREATE USER ''clustercheck''@''localhost'' IDENTIFIED BY ''${DB_CLUSTERCHECK_PASSWORD}'';"'
135                     - 'mysql -uroot -p"${DB_ROOT_PASSWORD}" -e "GRANT PROCESS ON *.* TO ''clustercheck''@''localhost'' WITH GRANT OPTION;"'
136                     - 'timeout ${DB_MAX_TIMEOUT} mysqladmin -uroot -p"${DB_ROOT_PASSWORD}" shutdown'
137             volumes: &mysql_volumes
138               list_concat:
139                 - {get_attr: [ContainersCommon, volumes]}
140                 -
141                   - /var/lib/kolla/config_files/mysql.json:/var/lib/kolla/config_files/config.json
142                   - /var/lib/config-data/puppet-generated/mysql/:/var/lib/kolla/config_files/src:ro
143                   - /var/lib/mysql:/var/lib/mysql
144             environment:
145               - KOLLA_CONFIG_STRATEGY=COPY_ALWAYS
146               - KOLLA_BOOTSTRAP=True
147               # NOTE(mandre) skip wsrep cluster status check
148               - KOLLA_KUBERNETES=True
149               - DB_MAX_TIMEOUT=60
150               -
151                 list_join:
152                   - '='
153                   - - 'DB_CLUSTERCHECK_PASSWORD'
154                     - {get_param: MysqlClustercheckPassword}
155               -
156                 list_join:
157                   - '='
158                   - - 'DB_ROOT_PASSWORD'
159                     -
160                       yaql:
161                         expression: $.data.passwords.where($ != '').first()
162                         data:
163                           passwords:
164                             - {get_param: MysqlRootPassword}
165                             - {get_param: [DefaultPasswords, mysql_root_password]}
166         step_2:
167           mysql_init_bundle:
168             start_order: 1
169             detach: false
170             net: host
171             user: root
172             command:
173               - '/bin/bash'
174               - '-c'
175               - str_replace:
176                   template:
177                     list_join:
178                       - '; '
179                       - - "cp -a /tmp/puppet-etc/* /etc/puppet; echo '{\"step\": 2}' > /etc/puppet/hieradata/docker.json"
180                         - "FACTER_uuid=docker puppet apply --tags file,file_line,concat,augeas,TAGS -v -e 'CONFIG'"
181                   params:
182                     TAGS: 'pacemaker::resource::bundle,pacemaker::property,pacemaker::resource::ocf,pacemaker::constraint::order,pacemaker::constraint::colocation,galera_ready,mysql_database,mysql_grant,mysql_user'
183                     CONFIG: 'include ::tripleo::profile::base::pacemaker;include ::tripleo::profile::pacemaker::database::mysql_bundle'
184             image: *mysql_image
185             volumes:
186               - /etc/hosts:/etc/hosts:ro
187               - /etc/localtime:/etc/localtime:ro
188               - /etc/puppet:/tmp/puppet-etc:ro
189               - /usr/share/openstack-puppet/modules:/usr/share/openstack-puppet/modules:ro
190               - /etc/corosync/corosync.conf:/etc/corosync/corosync.conf:ro
191               - /dev/shm:/dev/shm:rw
192               - /var/lib/mysql:/var/lib/mysql:rw
193       host_prep_tasks:
194         - name: create /var/lib/mysql
195           file:
196             path: /var/lib/mysql
197             state: directory
198       upgrade_tasks:
199         - name: get bootstrap nodeid
200           tags: common
201           command: hiera -c /etc/puppet/hiera.yaml bootstrap_nodeid
202           register: bootstrap_node
203         - name: set is_bootstrap_node fact
204           tags: common
205           set_fact: is_bootstrap_node={{bootstrap_node.stdout|lower == ansible_hostname|lower}}
206         - name: Disable the galera cluster resource
207           tags: step2
208           pacemaker_resource:
209             resource: galera
210             state: disable
211             wait_for_resource: true
212           when: is_bootstrap_node
213         - name: Delete the stopped galera cluster resource.
214           tags: step2
215           pacemaker_resource:
216             resource: galera
217             state: delete
218             wait_for_resource: true
219           when: is_bootstrap_node
220         - name: Disable mysql service
221           tags: step2
222           service: name=mariadb enabled=no