b933be96627b6fbc7daacefc6b1fe3a257cc4fa3
[apex-tripleo-heat-templates.git] / docker / services / database / mongodb.yaml
1 heat_template_version: pike
2
3 description: >
4   MongoDB service deployment using puppet and docker
5
6 parameters:
7   DockerMongodbImage:
8     description: image
9     type: string
10   DockerMongodbConfigImage:
11     description: The container image to use for the mongodb 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   RoleName:
32     default: ''
33     description: Role name on which the service is applied
34     type: string
35   RoleParameters:
36     default: {}
37     description: Parameters specific to the role
38     type: json
39   EnableInternalTLS:
40     type: boolean
41     default: false
42   InternalTLSCAFile:
43     default: '/etc/ipa/ca.crt'
44     type: string
45     description: Specifies the default CA cert to use if TLS is used for
46                  services in the internal network.
47
48 conditions:
49
50   internal_tls_enabled: {equals: [{get_param: EnableInternalTLS}, true]}
51
52 resources:
53
54   MongodbPuppetBase:
55     type: ../../../puppet/services/database/mongodb.yaml
56     properties:
57       EndpointMap: {get_param: EndpointMap}
58       ServiceData: {get_param: ServiceData}
59       ServiceNetMap: {get_param: ServiceNetMap}
60       DefaultPasswords: {get_param: DefaultPasswords}
61       RoleName: {get_param: RoleName}
62       RoleParameters: {get_param: RoleParameters}
63
64 outputs:
65   role_data:
66     description: Containerized service Mongodb using composable services.
67     value:
68       service_name: {get_attr: [MongodbPuppetBase, role_data, service_name]}
69       config_settings:
70         map_merge:
71           - get_attr: [MongodbPuppetBase, role_data, config_settings]
72           - mongodb::server::fork: false
73       logging_source: {get_attr: [MongodbPuppetBase, role_data, logging_source]}
74       logging_groups: {get_attr: [MongodbPuppetBase, role_data, logging_groups]}
75       step_config: &step_config
76         list_join:
77           - "\n"
78           - - "['Mongodb_database', 'Mongodb_user', 'Mongodb_replset'].each |String $val| { noop_resource($val) }"
79             - {get_attr: [MongodbPuppetBase, role_data, step_config]}
80       # BEGIN DOCKER SETTINGS #
81       puppet_config:
82         config_volume: mongodb
83         puppet_tags: file # set this even though file is the default
84         step_config: *step_config
85         config_image: &mongodb_config_image {get_param: DockerMongodbConfigImage}
86       kolla_config:
87         /var/lib/kolla/config_files/mongodb.json:
88           command: /usr/bin/mongod --unixSocketPrefix=/var/run/mongodb --config /etc/mongod.conf run
89           config_files:
90             - source: "/var/lib/kolla/config_files/src/*"
91               dest: "/"
92               merge: true
93               preserve_properties: true
94             - source: "/var/lib/kolla/config_files/src-tls/*"
95               dest: "/"
96               merge: true
97               preserve_properties: true
98           permissions:
99             - path: /var/lib/mongodb
100               owner: mongodb:mongodb
101               recurse: true
102             - path: /var/log/mongodb
103               owner: mongodb:mongodb
104               recurse: true
105             - path: /etc/pki/tls/certs/mongodb.pem
106               owner: mongodb:mongodb
107       docker_config:
108         step_2:
109           mongodb:
110             image: {get_param: DockerMongodbImage}
111             net: host
112             privileged: false
113             volumes: &mongodb_volumes
114               list_concat:
115                 - - /var/lib/kolla/config_files/mongodb.json:/var/lib/kolla/config_files/config.json
116                   - /var/lib/config-data/puppet-generated/mongodb/:/var/lib/kolla/config_files/src:ro
117                   - /etc/localtime:/etc/localtime:ro
118                   - /var/log/containers/mongodb:/var/log/mongodb
119                   - /var/lib/mongodb:/var/lib/mongodb
120                 - if:
121                   - internal_tls_enabled
122                   - - list_join:
123                       - ':'
124                       - - {get_param: InternalTLSCAFile}
125                         - {get_param: InternalTLSCAFile}
126                         - 'ro'
127                     - /etc/pki/tls/certs/mongodb.pem:/var/lib/kolla/config_files/src-tls/etc/pki/tls/certs/mongodb.pem:ro
128                   - null
129             environment:
130               - KOLLA_CONFIG_STRATEGY=COPY_ALWAYS
131       docker_puppet_tasks:
132         # MySQL database initialization occurs only on single node
133         step_2:
134           config_volume: 'mongodb_init_tasks'
135           puppet_tags: 'mongodb_database,mongodb_user,mongodb_replset'
136           step_config: 'include ::tripleo::profile::base::database::mongodb'
137           config_image: *mongodb_config_image
138           volumes:
139             list_concat:
140               - - /var/lib/mongodb:/var/lib/mongodb
141                 - /var/log/containers/mongodb:/var/log/mongodb
142               - if:
143                 - internal_tls_enabled
144                 - - list_join:
145                     - ':'
146                     - - {get_param: InternalTLSCAFile}
147                       - {get_param: InternalTLSCAFile}
148                       - 'ro'
149                   - /etc/pki/tls/certs/mongodb.pem:/var/lib/kolla/config_files/src-tls/etc/pki/tls/certs/mongodb.pem:ro
150                 - null
151       host_prep_tasks:
152         - name: create persistent directories
153           file:
154             path: "{{ item }}"
155             state: directory
156           with_items:
157             - /var/log/containers/mongodb
158             - /var/lib/mongodb
159       metadata_settings:
160         get_attr: [MongodbPuppetBase, role_data, metadata_settings]
161       upgrade_tasks:
162         - name: Check for mongodb service
163           stat: path=/usr/lib/systemd/system/mongod.service
164           tags: common
165           register: mongod_service
166         - name: Stop and disable mongodb service
167           tags: step2
168           service: name=mongod state=stopped enabled=no
169           when: mongod_service.stat.exists