User data for cloud servers
User data refers to user configuration parameters for the server's operating system. Using user data, you can automate server configuration. User parameters are described as scripts in the cloud-config format (text files with YAML syntax) or as a bash script. Scripts are automatically Base64-encoded, passed to the server, and executed using the cloud-init agent on first boot of the operating system.
For more information about cloud-config and bash script formats, see the User data formats guide in the cloud-init documentation.
You can specify user data when creating a cloud server. In scripts, you can pass parameters for configuring the operating system and scenarios. For example:
- create a directory and upload files to it;
- update repositories and install software packages;
- add SSH keys to the server;
- configure the resolv.conf DNS resolver configuration file .
See other examples in the Cloud config examples guide in 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 of additional settings, you can paste the script into the User data field, upload a file in
txt,gz, orshformat, or upload a MIME archive. The maximum size of a 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
Cloud-config
Bash script
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
Cloud-config
Bash script
Example script to install pwgen and pastebinit:
#cloud-config
package_update: true
packages:
- pwgen
- pastebinit
Place SSH keys on the server
Cloud-config
Bash script
Example script:
#cloud-config
ssh_authorized_keys:
- ssh-rsa AAAAB3N…V7NZ user1@host
- ssh-rsa AAAAB3N…NtHw== user2@server
Configure a configuration file
Cloud-config
Bash script
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