Skip to main content

User data for cloud servers

Last update:

User data is custom configuration parameters for the server operating system. You can use user data to automate server setup. Custom parameters are described as cloud-config scripts (text files with YAML syntax) or as bash scripts. The scripts are automatically encoded in Base64, sent to the server, and executed using the cloud-init agent during the first operating system boot.

Learn more about cloud-config and bash script formats in the User data formats section of the cloud-init documentation.

You can specify user data when creating a cloud server. You can pass operating system configuration parameters and scripts. For example, you can:

See other examples in the Cloud config examples section of the cloud-init documentation.

Specify user data

You can specify user data only when creating a cloud server:

  • in the Control Panel — at step 4 additional settings you can insert a script into the User data field, upload a file in txt, gz, sh format, or as a MIME archive. The maximum size of the script with data that is not Base64 encoded is 16 KB;
  • via OpenStack CLI and Terraform — only scripts with Base64 encoded data.

You cannot change the script after the server is created.

User data examples

Create a directory and upload files to it⁠

Example script to create a directory and download a file to it over a network:

#cloud-config
runcmd:
- mkdir /run/newdir
- [ wget, "http://example.com", -O, /run/newdir/index.html ]

Update repositories and install packages

Example script to install pwgen and pastebinit:

#cloud-config
package_update: true
packages:
- pwgen
- pastebinit

Place SSH keys on the server

Example script:

#cloud-config
ssh_authorized_keys:
- ssh-rsa AAAAB3N…V7NZ user1@host
- ssh-rsa AAAAB3N…NtHw== user2@server

Configure a configuration file

example script for the resolv.conf DNS resolver:

#cloud-config
manage_resolv_conf: true
resolv_conf:
nameservers: ['4.4.4.4', '8.8.8.8']
searchdomains:
- foo.example.com
- bar.example.com
domain: example.com
options:
rotate: true
timeout: 1