ce65dacbf05d05bd0585a87eb694309303b0c409
[apex-tripleo-heat-templates.git] / extraconfig / all_nodes / swap.j2.yaml
1 heat_template_version: 2014-10-16
2
3 description: >
4   Extra config to add swap space to nodes.
5
6 # Parameters passed from the parent template - note if you maintain
7 # out-of-tree templates they may require additional parameters if the
8 # in-tree templates add a new role.
9 parameters:
10   servers:
11     type: json
12   swap_size_megabytes:
13     type: string
14     description: Amount of swap space to allocate in megabytes
15     default: '4096'
16   swap_path:
17     type: string
18     description: Full path to location of swap file
19     default: '/swap'
20
21
22 resources:
23
24   SwapConfig:
25     type: OS::Heat::SoftwareConfig
26     properties:
27       group: script
28       config: |
29         #!/bin/bash
30         set -eux
31         if [ ! -f $swap_path ]; then
32           dd if=/dev/zero of=$swap_path count=$swap_size_megabytes bs=1M
33           chmod 0600 $swap_path
34           mkswap $swap_path
35           swapon $swap_path
36         else
37           echo "$swap_path already exists"
38         fi
39         echo "$swap_path swap swap defaults 0 0" >> /etc/fstab
40       inputs:
41         - name: swap_size_megabytes
42           description: Amount of swap space to allocate in megabytes
43           default: '4096'
44         - name: swap_path
45           description: Full path to location of swap file
46           default: '/swap'
47
48 {% for role in roles %}
49   {{role.name}}SwapDeployment:
50     type: OS::Heat::SoftwareDeploymentGroup
51     properties:
52       config: {get_resource: SwapConfig}
53       servers: {get_param: [servers, {{role.name}}]}
54       input_values:
55         swap_size_megabytes: {get_param: swap_size_megabytes}
56         swap_path: {get_param: swap_path}
57       actions: ["CREATE"]
58 {% endfor %}