75ffc9e6f53199dc71ab4b307b26b174720fa8c1
[apex-tripleo-heat-templates.git] / extraconfig / all_nodes / mac_hostname.j2.yaml
1 heat_template_version: 2014-10-16
2
3 description: >
4   Example extra config for cluster config
5   this example collects the hostname and MAC addresses for each node in
6   the deployment, then distributes that info to all Controller nodes.
7
8 # Parameters passed from the parent template - note if you maintain
9 # out-of-tree templates they may require additional parameters if the
10 # in-tree templates add a new role.
11 parameters:
12   servers:
13     type: json
14 # Note extra parameters can be defined, then passed data via the
15 # environment parameter_defaults, without modifying the parent template
16
17 resources:
18
19   CollectMacConfig:
20     type: OS::Heat::SoftwareConfig
21     properties:
22       group: script
23       config: |
24         #!/bin/sh
25         MACS=$(ifconfig  | grep ether | awk '{print $2}' | tr "\n" " ")
26         HOSTNAME=$(hostname -s)
27         echo "$HOSTNAME $MACS"
28
29   # FIXME(shardy): Long term it'd be better if Heat SoftwareDeployments accepted
30   # list instead of a map, then we could join the lists of servers into one
31   # deployment instead of requiring one deployment per-role.
32 {% for role in roles %}
33   CollectMacDeployments{{role.name}}:
34     type: OS::Heat::SoftwareDeployments
35     properties:
36       name: CollectMacDeploymentsController
37       servers:  {get_param: [servers, {{role.name}}]}
38       config: {get_resource: CollectMacConfig}
39       actions: ['CREATE'] # Only do this on CREATE
40 {% endfor %}
41
42   # Now we distribute all-the-macs to all Controller nodes
43   DistributeMacConfig:
44     type: OS::Heat::SoftwareConfig
45     properties:
46       group: script
47       inputs:
48       - name: controller_mappings
49       - name: compute_mappings
50       - name: blockstorage_mappings
51       - name: objectstorage_mappings
52       - name: cephstorage_mappings
53       config: |
54         #!/bin/sh
55         echo $controller_mappings > /root/controller_mappings
56         echo $compute_mappings > /root/compute_mappings
57         echo $blockstorage_mappings > /root/blockstorage_mappings
58         echo $objectstorage_mappings > /root/objectstorage_mappings
59         echo $cephstorage_mappings > /root/cephstorage_mappings
60         echo "mappings = $(cat /root/*_mappings)"
61
62   DistributeMacDeploymentsController:
63     type: OS::Heat::SoftwareDeployments
64     properties:
65       name: DistributeMacDeploymentsController
66       servers:  {get_param: [servers, Controller]}
67       config: {get_resource: DistributeMacConfig}
68       input_values:
69         # FIXME(shardy): It'd be more convenient if we could join these
70         # items together but because the returned format is a map (not a list)
71         # we can't use list_join or str_replace.  Possible Heat TODO.
72         controller_mappings: {get_attr: [CollectMacDeploymentsController, deploy_stdouts]}
73         compute_mappings: {get_attr: [CollectMacDeploymentsCompute, deploy_stdouts]}
74         blockstorage_mappings: {get_attr: [CollectMacDeploymentsBlockStorage, deploy_stdouts]}
75         objectstorage_mappings: {get_attr: [CollectMacDeploymentsObjectStorage, deploy_stdouts]}
76         cephstorage_mappings: {get_attr: [CollectMacDeploymentsCephStorage, deploy_stdouts]}
77       actions: ['CREATE'] # Only do this on CREATE