aboutsummaryrefslogtreecommitdiffstats
path: root/docker/post.j2.yaml
blob: c125423d12f94ae26d87e30ac4c5643e1fe7ba5e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
# certain initialization steps (run in a container) will occur
# on the first role listed in the roles file
{% set primary_role_name = roles[0].name -%}

heat_template_version: ocata

description: >
  Post-deploy configuration steps via puppet for all roles,
  as defined in ../roles_data.yaml

parameters:
  servers:
    type: json
    description: Mapping of Role name e.g Controller to a list of servers
  role_data:
    type: json
    description: Mapping of Role name e.g Controller to the per-role data
  DeployIdentifier:
    default: ''
    type: string
    description: >
      Setting this to a unique value will re-run any deployment tasks which
      perform configuration on a Heat stack-update.
  EndpointMap:
    default: {}
    description: Mapping of service endpoint -> protocol. Typically set
                 via parameter_defaults in the resource registry.
    type: json

resources:

{% for role in roles %}
  # Post deployment steps for all roles
  # A single config is re-applied with an incrementing step number
  # {{role.name}} Role steps
  {{role.name}}ArtifactsConfig:
    type: ../puppet/deploy-artifacts.yaml

  {{role.name}}ArtifactsDeploy:
    type: OS::Heat::StructuredDeploymentGroup
    properties:
      servers:  {get_param: [servers, {{role.name}}]}
      config: {get_resource: {{role.name}}ArtifactsConfig}

  {{role.name}}PreConfig:
    type: OS::TripleO::Tasks::{{role.name}}PreConfig
    properties:
      servers: {get_param: [servers, {{role.name}}]}
      input_values:
        update_identifier: {get_param: DeployIdentifier}

  {{role.name}}CreateConfigDir:
    type: OS::Heat::SoftwareConfig
    properties:
      group: script
      config: {get_file: create-config-dir.sh}

  {{role.name}}CreateConfigDirDeployment:
    type: OS::Heat::SoftwareDeploymentGroup
    properties:
      servers: {get_param: [servers, {{role.name}}]}
      config: {get_resource: {{role.name}}CreateConfigDir}

  # this creates a JSON config file for our docker-puppet.py script
  {{role.name}}GenPuppetConfig:
    type: OS::Heat::StructuredConfig
    properties:
      group: json-file
      config:
        /var/lib/docker-puppet/docker-puppet.json:
          yaql:
            # select only services that have a non-null config_image with
            # a step_config as well
            expression:
              $.data.config_volume.zip($.data.puppet_tags, $.data.step_config, $.data.config_image).where($[3] != null and $[1] != null)
            data:
              config_volume: {get_param: [role_data, {{role.name}}, config_volume]}
              step_config: {get_param: [role_data, {{role.name}}, step_config]}
              puppet_tags: {get_param: [role_data, {{role.name}}, puppet_tags]}
              config_image: {get_param: [role_data, {{role.name}}, config_image]}

  {{role.name}}GenPuppetDeployment:
    type: OS::Heat::SoftwareDeploymentGroup
    properties:
      servers: {get_param: [servers, {{role.name}}]}
      config: {get_resource: {{role.name}}GenPuppetConfig}

  {{role.name}}GenerateConfig:
    type: OS::Heat::SoftwareConfig
    properties:
      group: script
      config: {get_file: docker-puppet.py}

  {{role.name}}GenerateConfigDeployment:
    type: OS::Heat::SoftwareDeploymentGroup
    depends_on: [{{role.name}}GenPuppetDeployment, {{role.name}}ArtifactsDeploy, {{role.name}}CreateConfigDirDeployment]
    properties:
      name: {{role.name}}GenerateConfigDeployment
      servers: {get_param: [servers, {{role.name}}]}
      config: {get_resource: {{role.name}}GenerateConfig}

  {{role.name}}PuppetStepConfig:
    type: OS::Heat::Value
    properties:
      type: string
      value:
        yaql:
          expression:
            # select 'step_config' only from services that do not have a docker_image
            $.data.service_names.zip($.data.step_config, $.data.docker_image).where($[2] = null).where($[1] != null).select($[1]).join("\n")
          data:
            service_names: {get_param: [role_data, {{role.name}}, service_names]}
            step_config: {get_param: [role_data, {{role.name}}, step_config]}
            docker_image: {get_param: [role_data, {{role.name}}, docker_image]}

  {{role.name}}DockerConfig:
    type: OS::Heat::Value
    properties:
      type: json
      value:
        yaql:
          expression:
            # select 'docker_config' only from services that have a docker_image
            $.data.service_names.zip($.data.docker_config, $.data.docker_image).where($[2] != null).select($[1]).reduce($1.mergeWith($2), {})
          data:
            service_names: {get_param: [role_data, {{role.name}}, service_names]}
            docker_config: {get_param: [role_data, {{role.name}}, docker_config]}
            docker_image: {get_param: [role_data, {{role.name}}, docker_image]}

  {{role.name}}KollaJsonConfig:
    type: OS::Heat::StructuredConfig
    properties:
      group: json-file
      config:
        {get_param: [role_data, {{role.name}}, kolla_config]}

  {{role.name}}KollaJsonDeployment:
    type: OS::Heat::SoftwareDeploymentGroup
    properties:
      name: {{role.name}}KollaJsonDeployment
      config: {get_resource: {{role.name}}KollaJsonConfig}
      servers: {get_param: [servers, {{role.name}}]}

  # BEGIN BAREMETAL CONFIG STEPS

  {% if role.name == 'Controller' %}
  ControllerPrePuppet:
    type: OS::TripleO::Tasks::ControllerPrePuppet
    properties:
      servers: {get_param: [servers, Controller]}
      input_values:
        update_identifier: {get_param: DeployIdentifier}
  {% endif %}

  {{role.name}}Config:
    type: OS::TripleO::{{role.name}}Config
    properties:
      StepConfig: {get_attr: [{{role.name}}PuppetStepConfig, value]}

  {% for step in range(1, 6) %}

  {{role.name}}Deployment_Step{{step}}:
    type: OS::Heat::StructuredDeploymentGroup
  {% if step == 1 %}
    depends_on: [{{role.name}}PreConfig, {{role.name}}ArtifactsDeploy]
  {% else %}
    depends_on:
    {% for dep in roles %}
      - {{dep.name}}Deployment_Step{{step -1}}
      - {{dep.name}}ContainersDeployment_Step{{step -1}}
    {% endfor %}
  {% endif %}
    properties:
      name: {{role.name}}Deployment_Step{{step}}
      servers: {get_param: [servers, {{role.name}}]}
      config: {get_resource: {{role.name}}Config}
      input_values:
        step: {{step}}
        update_identifier: {get_param: DeployIdentifier}

  {% endfor %}
  # END BAREMETAL CONFIG STEPS

  # BEGIN CONTAINER CONFIG STEPS
  {% for step in range(1, 6) %}

  {{role.name}}ContainersConfig_Step{{step}}:
    type: OS::Heat::StructuredConfig
    properties:
      group: docker-cmd
      config:
        {get_attr: [{{role.name}}DockerConfig, value, step_{{step}}]}

  {{role.name}}ContainersDeployment_Step{{step}}:
    type: OS::Heat::StructuredDeploymentGroup
  {% if step == 1 %}
    depends_on:
      - {{role.name}}PreConfig
      - {{role.name}}KollaJsonDeployment
      - {{role.name}}GenPuppetDeployment
      - {{role.name}}GenerateConfigDeployment
  {% else %}
    depends_on:
      {% for dep in roles %}
        - {{dep.name}}ContainersDeployment_Step{{step -1}}
        - {{dep.name}}Deployment_Step{{step}} # baremetal steps of the same level run first
        - {{dep.name}}Deployment_Step{{step -1}}
      {% endfor %}
  {% endif %}
    properties:
      name: {{role.name}}ContainersDeployment_Step{{step}}
      servers: {get_param: [servers, {{role.name}}]}
      config: {get_resource: {{role.name}}ContainersConfig_Step{{step}}}

  {% endfor %}
  # END CONTAINER CONFIG STEPS

  {{role.name}}PostConfig:
    type: OS::TripleO::Tasks::{{role.name}}PostConfig
    depends_on:
  {% for dep in roles %}
      - {{dep.name}}Deployment_Step5
  {% endfor %}
    properties:
      servers:  {get_param: servers}
      input_values:
        update_identifier: {get_param: DeployIdentifier}

  # Note, this should come last, so use depends_on to ensure
  # this is created after any other resources.
  {{role.name}}ExtraConfigPost:
    depends_on:
  {% for dep in roles %}
      - {{dep.name}}PostConfig
  {% endfor %}
    type: OS::TripleO::NodeExtraConfigPost
    properties:
        servers: {get_param: [servers, {{role.name}}]}

  {% if role.name == 'Controller' %}
  ControllerPostPuppet:
    depends_on:
      - ControllerExtraConfigPost
    type: OS::TripleO::Tasks::ControllerPostPuppet
    properties:
      servers: {get_param: [servers, Controller]}
      input_values:
        update_identifier: {get_param: DeployIdentifier}
  {% endif %}

{% endfor %}