Update the template_version alias for all the templates to pike.
[apex-tripleo-heat-templates.git] / firstboot / userdata_example.yaml
1 heat_template_version: pike
2
3 # NOTE: You don't need to pass the parameter explicitly from the
4 # parent template, it can be specified via the parameter_defaults
5 # in the resource_registry instead, if you want to override the default
6 # and/or share values with other templates in the tree.
7 parameters:
8   extra_username:
9     type: string
10     default: extrauser
11
12 description: >
13   This is an example showing how you can do firstboot configuration
14   of the nodes via cloud-init.  To enable this, replace the default
15   mapping of OS::TripleO::NodeUserData in ../overcloud_resource_registry*
16
17 resources:
18   userdata:
19     type: OS::Heat::MultipartMime
20     properties:
21       parts:
22       - config: {get_resource: user_config}
23       - config: {get_resource: ssh_config}
24
25   # Get cloud-init to create an extra user, in addition to the default for the
26   # distro.  Note there are various options, including configuring ssh keys,
27   # but atm I can only see how to specify the keys explicitly, not via metadata
28   user_config:
29     type: OS::Heat::CloudConfig
30     properties:
31       cloud_config:
32         users:
33         - default
34         - name: {get_param: extra_username}
35
36   # Setup ssh key for the extra user to match the key installed for the default
37   # user, e.g that provided via the nova keypair on instance boot
38   ssh_config:
39     type: OS::Heat::SoftwareConfig
40     properties:
41       config:
42         str_replace:
43           template: |
44             #!/bin/bash
45             curl http://169.254.169.254/openstack/2012-08-10/meta_data.json -o /root/meta_data.json
46             mkdir -p /home/$user/.ssh
47             chmod 700 /home/$user/.ssh
48             cat /root/meta_data.json | jq -r ".keys[0].data" > /home/$user/.ssh/authorized_keys
49             chmod 600 /home/$user/.ssh/authorized_keys
50             chown -R $user:$user /home/$user/.ssh
51           params:
52             $user: {get_param: extra_username}
53
54 outputs:
55   # This means get_resource from the parent template will get the userdata, see:
56   # http://docs.openstack.org/developer/heat/template_guide/composition.html#making-your-template-resource-more-transparent
57   # Note this is new-for-kilo, an alternative is returning a value then using
58   # get_attr in the parent template instead.
59   OS::stack_id:
60     value: {get_resource: userdata}