Merge "Fix cidr get_attr in custom networks"
[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             mkdir -p /home/$user/.ssh
46             chmod 700 /home/$user/.ssh
47             os-apply-config --key public-keys.0.openssh-key --type raw > /home/$user/.ssh/authorized_keys
48             chmod 600 /home/$user/.ssh/authorized_keys
49             chown -R $user:$user /home/$user/.ssh
50           params:
51             $user: {get_param: extra_username}
52
53 outputs:
54   # This means get_resource from the parent template will get the userdata, see:
55   # http://docs.openstack.org/developer/heat/template_guide/composition.html#making-your-template-resource-more-transparent
56   # Note this is new-for-kilo, an alternative is returning a value then using
57   # get_attr in the parent template instead.
58   OS::stack_id:
59     value: {get_resource: userdata}