66When the stack has been successfully created/updated the stack output is stored
77in the ` stack_outputs ` fact, and also written to file.
88
9+ ## Role Variables
10+
11+ - ` os_cloud ` : OpenStack cloud name from clouds.yaml
12+ - ` stack_name ` : Name of the Heat stack to create/update
13+ - ` stack_template_path ` : Path to the Heat template file
14+ - ` stack_parameters ` : Dictionary of parameters to pass to the Heat template
15+ - ` compress_heat_files ` : (Optional) List of file archives to compress for use as user data. Each item should define:
16+ - ` archive ` : Base name for the archive (without extension)
17+ - ` files ` : List of files to include in the tar.gz archive
18+
919## Example playbook
1020
1121``` yaml
@@ -21,3 +31,57 @@ in the `stack_outputs` fact, and also written to file.
2131 stack_template_path : " {{ stack_template_path }}"
2232 stack_parameters : " {{ stack_parameters }}"
2333` ` `
34+
35+ ## Compressing files for user data
36+
37+ When you need to pass multiple files as user data to instances, you can use the
38+ ` compress_heat_files` variable to create compressed tar archives that are base64
39+ encoded. This is useful for passing scripts, configuration files, or other data
40+ that instances need at boot time.
41+
42+ ` ` ` yaml
43+ - name: Deploy stack with compressed user data
44+ hosts: localhost
45+ roles:
46+ - role: heat_stack
47+ vars:
48+ ...
49+ compress_heat_files:
50+ - archive: "data"
51+ files:
52+ - "script.sh"
53+ - "config.yaml"
54+ - "setup.py"
55+ ` ` `
56+
57+ The role will create `data.tar.gz` and `data.tar.gz.b64` files in the same
58+ directory as the stack template. The base64-encoded version can then be referenced
59+ in your Heat template using `get_file`.
60+
61+ # ## Heat template example
62+
63+ ` ` ` yaml
64+ resources:
65+ server-write-files:
66+ type: OS::Heat::CloudConfig
67+ properties:
68+ cloud_config:
69+ write_files:
70+ - path: /tmp/data.tar.gz
71+ encoding: b64
72+ content: {get_file: archive.tar.gz.b64}
73+ owner: root:root
74+ permissions: '0644'
75+
76+ server-runcmd:
77+ type: OS::Heat::CloudConfig
78+ properties:
79+ cloud_config:
80+ runcmd:
81+ - ['tar', '-xzf', '/tmp/data.tar.gz', '-C', '/opt/']
82+ - ['chmod', '+x', '/opt/script.sh']
83+ - ['/opt/script.sh']
84+ ` ` `
85+
86+ This example writes the compressed archive to the instance, then extracts it and
87+ runs a script from the archive during instance initialization.
0 commit comments