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