Writing out arbitrary files

Encoding can be given as base64 (b64) or gzip. The content will be decoded accordingly and then written to the path provided.

For a full list of keys, refer to the write files module schema.

Write content to file

This example will write out base64-encoded content to /etc/sysconfig/selinux.

1#cloud-config
2write_files:
3- encoding: b64
4  content: CiMgVGhpcyBmaWxlIGNvbnRyb2xzIHRoZSBzdGF0ZSBvZiBTRUxpbnV4...
5  owner: root:root
6  path: /etc/sysconfig/selinux
7  permissions: '0644'

Append content to file

This config will append content to an existing file.

1#cloud-config
2write_files:
3- content: |
4    15 * * * * root ship_logs
5  path: /etc/crontab
6  append: true

Provide gzipped binary content

1#cloud-config
2write_files:
3- encoding: gzip
4  content: !!binary |
5      H4sIAIDb/U8C/1NW1E/KzNMvzuBKTc7IV8hIzcnJVyjPL8pJ4QIA6N+MVxsAAAA=
6  path: /usr/bin/hello
7  permissions: '0755'

Create empty file on the system

1#cloud-config
2write_files:
3- path: /root/CLOUD_INIT_WAS_HERE

Defer writing content

This example shows how to defer writing the file until after the packages have been installed and its user is created alongside.

 1#cloud-config
 2write_files:
 3- path: /etc/nginx/conf.d/example.com.conf
 4  content: |
 5    server {
 6        server_name example.com;
 7        listen 80;
 8        root /var/www;
 9        location / {
10            try_files $uri $uri/ $uri.html =404;
11        }
12    }
13  owner: 'nginx:nginx'
14  permissions: '0640'
15  defer: true