Merge "Stop also openstack-swift-object-expirer when upgrading swift services"
[apex-tripleo-heat-templates.git] / docker / services / pacemaker / rabbitmq.yaml
1 heat_template_version: pike
2
3 description: >
4   OpenStack containerized Rabbitmq service
5
6 parameters:
7   DockerRabbitmqImage:
8     description: image
9     type: string
10   DockerRabbitmqConfigImage:
11     description: The container image to use for the rabbitmq 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   RabbitCookie:
32     type: string
33     default: ''
34     hidden: true
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   RabbitmqBase:
47     type: ../../../puppet/services/rabbitmq.yaml
48     properties:
49       EndpointMap: {get_param: EndpointMap}
50       ServiceData: {get_param: ServiceData}
51       ServiceNetMap: {get_param: ServiceNetMap}
52       DefaultPasswords: {get_param: DefaultPasswords}
53       RoleName: {get_param: RoleName}
54       RoleParameters: {get_param: RoleParameters}
55
56 outputs:
57   role_data:
58     description: Role data for the Rabbitmq API role.
59     value:
60       service_name: {get_attr: [RabbitmqBase, role_data, service_name]}
61       config_settings:
62         map_merge:
63           - {get_attr: [RabbitmqBase, role_data, config_settings]}
64           - rabbitmq::service_manage: false
65             tripleo::profile::pacemaker::rabbitmq_bundle::rabbitmq_docker_image: &rabbitmq_image {get_param: DockerRabbitmqImage}
66       step_config: &step_config
67         get_attr: [RabbitmqBase, role_data, step_config]
68       service_config_settings: {get_attr: [RabbitmqBase, role_data, service_config_settings]}
69       # BEGIN DOCKER SETTINGS
70       puppet_config:
71         config_volume: rabbitmq
72         puppet_tags: file
73         step_config: *step_config
74         config_image: {get_param: DockerRabbitmqConfigImage}
75       kolla_config:
76         /var/lib/kolla/config_files/rabbitmq.json:
77           command: /usr/sbin/pacemaker_remoted
78           config_files:
79           - dest: /etc/libqb/force-filesystem-sockets
80             source: /dev/null
81             owner: root
82             perm: '0644'
83           - source: "/var/lib/kolla/config_files/src/*"
84             dest: "/"
85             merge: true
86             preserve_properties: true
87           permissions:
88            - path: /var/lib/rabbitmq
89              owner: rabbitmq:rabbitmq
90              recurse: true
91            - path: /var/log/rabbitmq
92              owner: rabbitmq:rabbitmq
93              recurse: true
94       # When using pacemaker we don't launch the container, instead that is done by pacemaker
95       # itself.
96       docker_config:
97         step_1:
98           rabbitmq_bootstrap:
99             start_order: 0
100             image: *rabbitmq_image
101             net: host
102             privileged: false
103             volumes:
104               - /var/lib/kolla/config_files/rabbitmq.json:/var/lib/kolla/config_files/config.json:ro
105               - /var/lib/config-data/puppet-generated/rabbitmq/:/var/lib/kolla/config_files/src:ro
106               - /etc/hosts:/etc/hosts:ro
107               - /etc/localtime:/etc/localtime:ro
108               - /var/lib/rabbitmq:/var/lib/rabbitmq
109             environment:
110               - KOLLA_CONFIG_STRATEGY=COPY_ALWAYS
111               - KOLLA_BOOTSTRAP=True
112               -
113                 list_join:
114                   - '='
115                   - - 'RABBITMQ_CLUSTER_COOKIE'
116                     -
117                       yaql:
118                         expression: $.data.passwords.where($ != '').first()
119                         data:
120                           passwords:
121                             - {get_param: RabbitCookie}
122                             - {get_param: [DefaultPasswords, rabbit_cookie]}
123         step_2:
124           rabbitmq_init_bundle:
125             start_order: 0
126             detach: false
127             net: host
128             user: root
129             command:
130               - '/bin/bash'
131               - '-c'
132               - str_replace:
133                   template:
134                     list_join:
135                       - '; '
136                       - - "cp -a /tmp/puppet-etc/* /etc/puppet; echo '{\"step\": 2}' > /etc/puppet/hieradata/docker.json"
137                         - "FACTER_uuid=docker puppet apply --tags file,file_line,concat,augeas,TAGS -v -e 'CONFIG'"
138                   params:
139                     TAGS: 'pacemaker::resource::bundle,pacemaker::property,pacemaker::resource::ocf,pacemaker::constraint::order,pacemaker::constraint::colocation'
140                     CONFIG: 'include ::tripleo::profile::base::pacemaker;include ::tripleo::profile::pacemaker::rabbitmq_bundle'
141             image: *rabbitmq_image
142             volumes:
143               - /etc/hosts:/etc/hosts:ro
144               - /etc/localtime:/etc/localtime:ro
145               - /etc/puppet:/tmp/puppet-etc:ro
146               - /usr/share/openstack-puppet/modules:/usr/share/openstack-puppet/modules:ro
147               - /etc/corosync/corosync.conf:/etc/corosync/corosync.conf:ro
148               - /dev/shm:/dev/shm:rw
149       host_prep_tasks:
150         - name: create /var/lib/rabbitmq
151           file:
152             path: /var/lib/rabbitmq
153             state: directory
154         - name: stop the Erlang port mapper on the host and make sure it cannot bind to the port used by container
155           shell: |
156             echo 'export ERL_EPMD_ADDRESS=127.0.0.1' > /etc/rabbitmq/rabbitmq-env.conf
157             echo 'export ERL_EPMD_PORT=4370' >> /etc/rabbitmq/rabbitmq-env.conf
158             for pid in $(pgrep epmd); do if [ "$(lsns -o NS -p $pid)" == "$(lsns -o NS -p 1)" ]; then kill $pid; break; fi; done
159       upgrade_tasks:
160         - name: get bootstrap nodeid
161           tags: common
162           command: hiera -c /etc/puppet/hiera.yaml bootstrap_nodeid
163           register: bootstrap_node
164         - name: set is_bootstrap_node fact
165           tags: common
166           set_fact: is_bootstrap_node={{bootstrap_node.stdout|lower == ansible_hostname|lower}}
167         - name: Disable the rabbitmq cluster resource.
168           tags: step2
169           pacemaker_resource:
170             resource: {get_attr: [RabbitmqBase, role_data, service_name]}
171             state: disable
172             wait_for_resource: true
173           when: is_bootstrap_node
174         - name: Delete the stopped rabbitmq cluster resource.
175           tags: step2
176           pacemaker_resource:
177             resource: {get_attr: [RabbitmqBase, role_data, service_name]}
178             state: delete
179             wait_for_resource: true
180           when: is_bootstrap_node
181         - name: Disable rabbitmq service
182           tags: step2
183           service: name=rabbitmq-server enabled=no