1c9af901ae4d72e2801a3298bcca658d9f517858
[apex-tripleo-heat-templates.git] / puppet / role.role.j2.yaml
1 heat_template_version: pike
2 description: 'OpenStack {{role.name}} node configured by Puppet'
3 parameters:
4   Overcloud{{role.name}}Flavor:
5     description: Flavor for the {{role.name}} node.
6     default: baremetal
7     type: string
8 {% if role.disable_constraints is not defined %}
9     constraints:
10       - custom_constraint: nova.flavor
11 {% endif %}
12   {{role.name}}Image:
13     type: string
14     default: overcloud-full
15 {% if role.disable_constraints is not defined %}
16     constraints:
17       - custom_constraint: glance.image
18 {% endif %}
19   ImageUpdatePolicy:
20     default: 'REBUILD_PRESERVE_EPHEMERAL'
21     description: What policy to use when reconstructing instances. REBUILD for rebuilds, REBUILD_PRESERVE_EPHEMERAL to preserve /mnt.
22     type: string
23   KeyName:
24     description: Name of an existing Nova key pair to enable SSH access to the instances
25     type: string
26     default: default
27 {% if role.disable_constraints is not defined %}
28     constraints:
29       - custom_constraint: nova.keypair
30 {% endif %}
31   NeutronPhysicalBridge:
32     default: 'br-ex'
33     description: An OVS bridge to create for accessing tenant networks.
34     type: string
35   NeutronPublicInterface:
36     default: nic1
37     description: Which interface to add to the NeutronPhysicalBridge.
38     type: string
39   ServiceNetMap:
40     default: {}
41     description: Mapping of service_name -> network name. Typically set
42                  via parameter_defaults in the resource registry.
43     type: json
44   EndpointMap:
45     default: {}
46     description: Mapping of service endpoint -> protocol. Typically set
47                  via parameter_defaults in the resource registry.
48     type: json
49   UpdateIdentifier:
50     default: ''
51     type: string
52     description: >
53       Setting to a previously unused value during stack-update will trigger
54       package update on all nodes
55   Hostname:
56     type: string
57     default: '' # Defaults to Heat created hostname
58   HostnameMap:
59     type: json
60     default: {}
61     description: Optional mapping to override hostnames
62   ExtraConfig:
63     default: {}
64     description: |
65       Additional hiera configuration to inject into the cluster. Note
66       that {{role.name}}ExtraConfig takes precedence over ExtraConfig.
67     type: json
68   {{role.name}}ExtraConfig:
69     default: {}
70     description: |
71       Role specific additional hiera configuration to inject into the cluster.
72     type: json
73   {{role.name}}IPs:
74     default: {}
75     type: json
76   NetworkDeploymentActions:
77     type: comma_delimited_list
78     description: >
79       Heat action when to apply network configuration changes
80     default: ['CREATE']
81   SoftwareConfigTransport:
82     default: POLL_SERVER_CFN
83     description: |
84       How the server should receive the metadata required for software configuration.
85     type: string
86     constraints:
87     - allowed_values: [POLL_SERVER_CFN, POLL_SERVER_HEAT, POLL_TEMP_URL, ZAQAR_MESSAGE]
88   CloudDomain:
89     default: 'localdomain'
90     type: string
91     description: >
92       The DNS domain used for the hosts. This must match the
93       overcloud_domain_name configured on the undercloud.
94   {{role.name}}ServerMetadata:
95     default: {}
96     description: >
97       Extra properties or metadata passed to Nova for the created nodes in
98       the overcloud. It's accessible via the Nova metadata API. This option is
99       role-specific and is merged with the values given to the ServerMetadata
100       parameter.
101     type: json
102   ServerMetadata:
103     default: {}
104     description: >
105       Extra properties or metadata passed to Nova for the created nodes in
106       the overcloud. It's accessible via the Nova metadata API. This applies to
107       all roles and is merged with a role-specific metadata parameter.
108     type: json
109   {{role.name}}SchedulerHints:
110     type: json
111     description: Optional scheduler hints to pass to nova
112     default: {}
113   NodeIndex:
114     type: number
115     default: 0
116   ServiceConfigSettings:
117     type: json
118     default: {}
119   ServiceNames:
120     type: comma_delimited_list
121     default: []
122   MonitoringSubscriptions:
123     type: comma_delimited_list
124     default: []
125   ServiceMetadataSettings:
126     type: json
127     default: {}
128   ConfigCommand:
129     type: string
130     description: Command which will be run whenever configuration data changes
131     default: os-refresh-config --timeout 14400
132   ConfigCollectSplay:
133     type: number
134     default: 30
135     description: |
136       Maximum amount of time to possibly to delay configuation collection
137       polling. Defaults to 30 seconds. Set to 0 to disable it which will cause
138       the configuration collection to occur as soon as the collection process
139       starts.  This setting is used to prevent the configuration collection
140       processes from polling all at the exact same time.
141   LoggingSources:
142     type: json
143     default: []
144   LoggingGroups:
145     type: comma_delimited_list
146     default: []
147   UpgradeInitCommand:
148     type: string
149     description: |
150       Command or script snippet to run on all overcloud nodes to
151       initialize the upgrade process. E.g. a repository switch.
152     default: ''
153   UpgradeInitCommonCommand:
154     type: string
155     description: |
156       Common commands required by the upgrades process. This should not
157       normally be modified by the operator and is set and unset in the
158       major-upgrade-composable-steps.yaml and major-upgrade-converge.yaml
159       environment files.
160     default: ''
161   DeploymentServerBlacklistDict:
162     default: {}
163     type: json
164     description: >
165       Map of server hostnames to blacklist from any triggered
166       deployments. If the value is 1, the server will be blacklisted. This
167       parameter is generated from the parent template.
168   RoleParameters:
169     type: json
170     description: Role Specific Parameters
171     default: {}
172   DeploymentSwiftDataMap:
173     type: json
174     description: |
175       Map of servers to Swift container and object for storing deployment data.
176       The keys are the Heat assigned hostnames, and the value is a map of the
177       container/object name in Swift. Example value:
178         overcloud-controller-0:
179           container: overcloud-controller
180           object: 0
181         overcloud-controller-1:
182           container: overcloud-controller
183           object: 1
184         overcloud-controller-2:
185           container: overcloud-controller
186           object: 2
187         overcloud-novacompute-0:
188           container: overcloud-compute
189           object: 0
190     default: {}
191
192 conditions:
193   server_not_blacklisted:
194     not:
195       equals:
196         - {get_param: [DeploymentServerBlacklistDict, {get_param: Hostname}]}
197         - 1
198   deployment_swift_data_map_unset:
199     equals:
200       - get_param:
201           - DeploymentSwiftDataMap
202           - {get_param: Hostname}
203       - ""
204
205 resources:
206   {{role.name}}:
207     type: OS::TripleO::{{role.name}}Server
208     metadata:
209       os-collect-config:
210         command: {get_param: ConfigCommand}
211         splay: {get_param: ConfigCollectSplay}
212     properties:
213       image: {get_param: {{role.name}}Image}
214       image_update_policy: {get_param: ImageUpdatePolicy}
215       flavor: {get_param: Overcloud{{role.name}}Flavor}
216       key_name: {get_param: KeyName}
217       networks:
218         - network: ctlplane
219       user_data_format: SOFTWARE_CONFIG
220       user_data: {get_resource: UserData}
221       name:
222         str_replace:
223             template: {get_param: Hostname}
224             params: {get_param: HostnameMap}
225       software_config_transport: {get_param: SoftwareConfigTransport}
226       metadata:
227         map_merge:
228           - {get_param: ServerMetadata}
229           - {get_param: {{role.name}}ServerMetadata}
230           - {get_param: ServiceMetadataSettings}
231       scheduler_hints: {get_param: {{role.name}}SchedulerHints}
232       deployment_swift_data:
233         if:
234           - deployment_swift_data_map_unset
235           - {}
236           - {get_param: [DeploymentSwiftDataMap,
237                          {get_param: Hostname}]}
238
239   # Combine the NodeAdminUserData and NodeUserData mime archives
240   UserData:
241     type: OS::Heat::MultipartMime
242     properties:
243       parts:
244       - config: {get_resource: NodeAdminUserData}
245         type: multipart
246       - config: {get_resource: NodeUserData}
247         type: multipart
248       - config: {get_resource: RoleUserData}
249         type: multipart
250
251   # Creates the "heat-admin" user if configured via the environment
252   # Should return a OS::Heat::MultipartMime reference via OS::stack_id
253   NodeAdminUserData:
254     type: OS::TripleO::NodeAdminUserData
255
256   # For optional operator additional userdata
257   # Should return a OS::Heat::MultipartMime reference via OS::stack_id
258   NodeUserData:
259     type: OS::TripleO::NodeUserData
260
261   # For optional operator role-specific userdata
262   # Should return a OS::Heat::MultipartMime reference via OS::stack_id
263   RoleUserData:
264     type: OS::TripleO::{{role.name}}::NodeUserData
265
266   {%- for network in networks %}
267   {{network.name}}Port:
268     type: OS::TripleO::{{role.name}}::Ports::{{network.name}}Port
269     properties:
270       ControlPlaneIP: {get_attr: [{{role.name}}, networks, ctlplane, 0]}
271       IPPool: {get_param: {{role.name}}IPs}
272       NodeIndex: {get_param: NodeIndex}
273   {%- endfor %}
274
275   NetworkConfig:
276     type: OS::TripleO::{{role.name}}::Net::SoftwareConfig
277     properties:
278       ControlPlaneIp: {get_attr: [{{role.name}}, networks, ctlplane, 0]}
279   {%- for network in networks %}
280       {{network.name}}IpSubnet: {get_attr: [{{network.name}}Port, ip_subnet]}
281   {%- endfor %}
282
283   NetIpMap:
284     type: OS::TripleO::Network::Ports::NetIpMap
285     properties:
286       ControlPlaneIp: {get_attr: [{{role.name}}, networks, ctlplane, 0]}
287   {%- for network in networks %}
288       {{network.name}}Ip: {get_attr: [{{network.name}}Port, ip_address]}
289       {{network.name}}IpSubnet: {get_attr: [{{network.name}}Port, ip_subnet]}
290       {{network.name}}IpUri: {get_attr: [{{network.name}}Port, ip_address_uri]}
291   {%- endfor %}
292
293   NetHostMap:
294     type: OS::Heat::Value
295     properties:
296       type: json
297       value:
298         external:
299           fqdn:
300             list_join:
301             - '.'
302             - - {get_attr: [{{role.name}}, name]}
303               - external
304               - {get_param: CloudDomain}
305           short:
306             list_join:
307             - '.'
308             - - {get_attr: [{{role.name}}, name]}
309               - external
310         internal_api:
311           fqdn:
312             list_join:
313             - '.'
314             - - {get_attr: [{{role.name}}, name]}
315               - internalapi
316               - {get_param: CloudDomain}
317           short:
318             list_join:
319             - '.'
320             - - {get_attr: [{{role.name}}, name]}
321               - internalapi
322         storage:
323           fqdn:
324             list_join:
325             - '.'
326             - - {get_attr: [{{role.name}}, name]}
327               - storage
328               - {get_param: CloudDomain}
329           short:
330             list_join:
331             - '.'
332             - - {get_attr: [{{role.name}}, name]}
333               - storage
334         storage_mgmt:
335           fqdn:
336             list_join:
337             - '.'
338             - - {get_attr: [{{role.name}}, name]}
339               - storagemgmt
340               - {get_param: CloudDomain}
341           short:
342             list_join:
343             - '.'
344             - - {get_attr: [{{role.name}}, name]}
345               - storagemgmt
346         tenant:
347           fqdn:
348             list_join:
349             - '.'
350             - - {get_attr: [{{role.name}}, name]}
351               - tenant
352               - {get_param: CloudDomain}
353           short:
354             list_join:
355             - '.'
356             - - {get_attr: [{{role.name}}, name]}
357               - tenant
358         management:
359           fqdn:
360             list_join:
361             - '.'
362             - - {get_attr: [{{role.name}}, name]}
363               - management
364               - {get_param: CloudDomain}
365           short:
366             list_join:
367             - '.'
368             - - {get_attr: [{{role.name}}, name]}
369               - management
370         ctlplane:
371           fqdn:
372             list_join:
373             - '.'
374             - - {get_attr: [{{role.name}}, name]}
375               - ctlplane
376               - {get_param: CloudDomain}
377           short:
378             list_join:
379             - '.'
380             - - {get_attr: [{{role.name}}, name]}
381               - ctlplane
382
383   PreNetworkConfig:
384     type: OS::TripleO::{{role.name}}::PreNetworkConfig
385     properties:
386       server: {get_resource: {{role.name}}}
387       RoleParameters: {get_param: RoleParameters}
388       ServiceNames: {get_param: ServiceNames}
389
390   NetworkDeployment:
391     type: OS::TripleO::SoftwareDeployment
392     depends_on: PreNetworkConfig
393     properties:
394       name: NetworkDeployment
395       config: {get_resource: NetworkConfig}
396       server: {get_resource: {{role.name}}}
397       actions: {get_param: NetworkDeploymentActions}
398       input_values:
399         bridge_name: {get_param: NeutronPhysicalBridge}
400         interface_name: {get_param: NeutronPublicInterface}
401       actions:
402         if:
403           - server_not_blacklisted
404           - {get_param: NetworkDeploymentActions}
405           - []
406
407   {{role.name}}UpgradeInitConfig:
408     type: OS::Heat::SoftwareConfig
409     properties:
410       group: script
411       config:
412         list_join:
413         - ''
414         - - "#!/bin/bash\n\n"
415           - "if [[ -f /etc/resolv.conf.save ]] ; then rm /etc/resolv.conf.save; fi\n\n"
416           - get_param: UpgradeInitCommand
417           - get_param: UpgradeInitCommonCommand
418
419   # Note we may be able to make this conditional on UpgradeInitCommandNotEmpty
420   # but https://bugs.launchpad.net/heat/+bug/1649900 needs fixing first
421   {{role.name}}UpgradeInitDeployment:
422     type: OS::Heat::SoftwareDeployment
423     depends_on: NetworkDeployment
424     properties:
425       name: {{role.name}}UpgradeInitDeployment
426       server: {get_resource: {{role.name}}}
427       config: {get_resource: {{role.name}}UpgradeInitConfig}
428       actions:
429         if:
430           - server_not_blacklisted
431           - ['CREATE', 'UPDATE']
432           - []
433
434   {{role.name}}Deployment:
435     type: OS::Heat::StructuredDeployment
436     depends_on: {{role.name}}UpgradeInitDeployment
437     properties:
438       name: {{role.name}}Deployment
439       config: {get_resource: {{role.name}}Config}
440       server: {get_resource: {{role.name}}}
441       input_values:
442         enable_package_upgrade: {get_attr: [UpdateDeployment, update_managed_packages]}
443       actions:
444         if:
445           - server_not_blacklisted
446           - ['CREATE', 'UPDATE']
447           - []
448
449   {{role.name}}Config:
450     type: OS::Heat::StructuredConfig
451     properties:
452       group: hiera
453       config:
454         hierarchy:
455           - '"%{::uuid}"'
456           - heat_config_%{::deploy_config_name}
457           - config_step
458           - {{role.name.lower()}}_extraconfig
459           - extraconfig
460           - service_names
461           - service_configs
462           - {{role.name.lower()}}
463           - bootstrap_node # provided by allNodesConfig
464           - all_nodes # provided by allNodesConfig
465           - vip_data # provided by allNodesConfig
466           - '"%{::osfamily}"'
467         merge_behavior: deeper
468         datafiles:
469           service_names:
470             service_names: {get_param: ServiceNames}
471             sensu::subscriptions: {get_param: MonitoringSubscriptions}
472           service_configs:
473             map_replace:
474               - {get_param: ServiceConfigSettings}
475               - values: {get_attr: [NetIpMap, net_ip_map]}
476           {{role.name.lower()}}_extraconfig: {get_param: {{role.name}}ExtraConfig}
477           extraconfig: {get_param: ExtraConfig}
478           {{role.name.lower()}}:
479             tripleo::packages::enable_upgrade: {get_input: enable_package_upgrade}
480             tripleo::profile::base::logging::fluentd::fluentd_sources: {get_param: LoggingSources}
481             tripleo::profile::base::logging::fluentd::fluentd_groups: {get_param: LoggingGroups}
482             fqdn_internal_api: {get_attr: [NetHostMap, value, internal_api, fqdn]}
483             fqdn_storage: {get_attr: [NetHostMap, value, storage, fqdn]}
484             fqdn_storage_mgmt: {get_attr: [NetHostMap, value, storage_mgmt, fqdn]}
485             fqdn_tenant: {get_attr: [NetHostMap, value, tenant, fqdn]}
486             fqdn_management: {get_attr: [NetHostMap, value, management, fqdn]}
487             fqdn_ctlplane: {get_attr: [NetHostMap, value, ctlplane, fqdn]}
488             fqdn_external: {get_attr: [NetHostMap, value, external, fqdn]}
489
490   # Resource for site-specific injection of root certificate
491   NodeTLSCAData:
492     depends_on: {{role.name}}Deployment
493     type: OS::TripleO::NodeTLSCAData
494     properties:
495       server: {get_resource: {{role.name}}}
496
497   # Hook for site-specific additional pre-deployment config, e.g extra hieradata
498   {{role.name}}ExtraConfigPre:
499     depends_on: {{role.name}}Deployment
500     type: OS::TripleO::{{role.name}}ExtraConfigPre
501     properties:
502         server: {get_resource: {{role.name}}}
503
504   # Hook for site-specific additional pre-deployment config,
505   # applying to all nodes, e.g node registration/unregistration
506   NodeExtraConfig:
507     depends_on: [{{role.name}}ExtraConfigPre, NodeTLSCAData]
508     type: OS::TripleO::NodeExtraConfig
509     properties:
510         server: {get_resource: {{role.name}}}
511
512   UpdateConfig:
513     type: OS::TripleO::Tasks::PackageUpdate
514
515   UpdateDeployment:
516     type: OS::Heat::SoftwareDeployment
517     depends_on: NetworkDeployment
518     properties:
519       name: UpdateDeployment
520       config: {get_resource: UpdateConfig}
521       server: {get_resource: {{role.name}}}
522       input_values:
523         update_identifier:
524           get_param: UpdateIdentifier
525       actions:
526         if:
527           - server_not_blacklisted
528           - ['CREATE', 'UPDATE']
529           - []
530
531   SshHostPubKey:
532     type: OS::TripleO::Ssh::HostPubKey
533     depends_on: {{role.name}}Deployment
534     properties:
535         server: {get_resource: {{role.name}}}
536
537 outputs:
538   ip_address:
539     description: IP address of the server in the ctlplane network
540     value: {get_attr: [{{role.name}}, networks, ctlplane, 0]}
541   hostname:
542     description: Hostname of the server
543     value: {get_attr: [{{role.name}}, name]}
544   hostname_map:
545     description: Mapping of network names to hostnames
546     value:
547   {%- for network in networks %}
548       {{network.name_lower|default(network.name.lower())}}: {get_attr: [NetHostMap, value, {{network.name_lower|default(network.name.lower()) }}, fqdn]}
549   {%- endfor %}
550       ctlplane: {get_attr: [NetHostMap, value, ctlplane, fqdn]}
551   hosts_entry:
552     value:
553       str_replace:
554         template: |
555           PRIMARYIP PRIMARYHOST.DOMAIN PRIMARYHOST
556   {%- for network in networks %}
557           {{network.name}}IP {{network.name}}HOST.DOMAIN {{network.name}}HOST
558   {%- endfor %}
559           CTLPLANEIP CTLPLANEHOST.DOMAIN CTLPLANEHOST
560         params:
561           PRIMARYIP: {get_attr: [NetIpMap, net_ip_map, {get_param: [ServiceNetMap, {{role.name}}HostnameResolveNetwork]}]}
562           DOMAIN: {get_param: CloudDomain}
563           PRIMARYHOST: {get_attr: [{{role.name}}, name]}
564   {%- for network in networks %}
565           {{network.name}}IP: {get_attr: [{{network.name}}Port, ip_address]}
566           {{network.name}}HOST: {get_attr: [NetHostMap, value, {{network.name_lower|default(network.name.lower())}}, short]}
567   {%- endfor %}
568           CTLPLANEIP: {get_attr: [{{role.name}}, networks, ctlplane, 0]}
569           CTLPLANEHOST: {get_attr: [NetHostMap, value, ctlplane, short]}
570   known_hosts_entry:
571     description: Entry for ssh known hosts
572     value:
573       str_replace:
574         template: "PRIMARYIP,PRIMARYHOST.DOMAIN,PRIMARYHOST,\
575   {%- for network in networks %}
576 {{network.name}}IP,{{network.name}}HOST.DOMAIN,{{network.name}}HOST,\
577   {%- endfor %}
578 CTLPLANEIP,CTLPLANEHOST.DOMAIN,CTLPLANEHOST HOSTSSHPUBKEY"
579         params:
580           PRIMARYIP: {get_attr: [NetIpMap, net_ip_map, {get_param: [ServiceNetMap, {{role.name}}HostnameResolveNetwork]}]}
581           DOMAIN: {get_param: CloudDomain}
582           PRIMARYHOST: {get_attr: [{{role.name}}, name]}
583   {%- for network in networks %}
584           {{network.name}}IP: {get_attr: [{{network.name}}Port, ip_address]}
585           {{network.name}}HOST: {get_attr: [NetHostMap, value, {{network.name_lower|default(network.name.lower())}}, short]}
586   {%- endfor %}
587           CTLPLANEIP: {get_attr: [{{role.name}}, networks, ctlplane, 0]}
588           CTLPLANEHOST: {get_attr: [NetHostMap, value, ctlplane, short]}
589           HOSTSSHPUBKEY: {get_attr: [SshHostPubKey, ecdsa]}
590   nova_server_resource:
591     description: Heat resource handle for {{role.name}} server
592     value:
593       {get_resource: {{role.name}}}
594     condition: server_not_blacklisted
595   deployed_server_port_map:
596     description: |
597       Map of Heat created hostname of the server to ip address. This is the
598       hostname before it has been mapped with the HostnameMap parameter, and
599       the IP address from the ctlplane network. This map can be used to construct
600       the DeployedServerPortMap parameter when using split-stack.
601     value:
602       map_replace:
603         - hostname:
604             fixed_ips:
605               - ip_address: {get_attr: [{{role.name}}, networks, ctlplane, 0]}
606         - keys:
607             hostname:
608               list_join:
609                 - '-'
610                 - - {get_param: Hostname}
611                   - ctlplane
612   deployed_server_deployment_swift_data_map:
613     description:
614       Map of Heat created hostname of the server to the Swift container and object
615       used to created the temporary url for metadata polling with
616       os-collect-config.
617     value:
618       map_replace:
619         - hostname:
620             container:
621               str_split:
622                 - '/'
623                 - {get_attr: [{{role.name}}, os_collect_config, request, metadata_url]}
624                 - 5
625             object:
626               str_split:
627                 - '?'
628                 - str_split:
629                     - '/'
630                     - {get_attr: [{{role.name}}, os_collect_config, request, metadata_url]}
631                     - 6
632                 - 0
633         - keys: {hostname: {get_param: Hostname}}
634   os_collect_config:
635     description: The os-collect-config configuration associated with this server resource
636     value: {get_attr: [{{role.name}}, os_collect_config]}
637   {%- for network in networks %}
638   {{network.name_lower|default(network.name.lower())}}_ip_address:
639     description: IP address of the server in the {{network.name}} network
640     value: {get_attr: [{{network.name}}Port, ip_address]}
641   {%- endfor %}