User data
User data — user configuration parameters of the server operating system. They are described as scripts in cloud-config format (text files with YAML syntax) or as a bash script. The scripts are automatically encoded in Base64, transferred to the server and executed with the help of the agent cloud-init when the operating system is first started. Using user data helps automate server configuration.
Specify user data you can when you create a cloud server.
Read more about cloud-config and bash script formats in the instructions User data formats cloud-init documentation.
In scripts, you can pass parameters to configure the operating system and scripts. For example:
- create a directory and upload files to it;
- update repositories and install software packages;
- place SSH keys on the server;
- configure the domain name resolver configuration file resolv.conf.
Check out the other examples in the manual Cloud config examples cloud-init documentation.
Specify user data
User data can only be specified when cloud server creation:
- in the control panel — at step 14 you can insert text into the field User data, download the file in formats
txt
,gz
,sh
or MIME archive. The maximum size of a script with non-Base64 encoded data is 16 KB; - through the OpenStack CLI and Terraform — only scripts with Base64 encoded data.
Once the server is created, you cannot change the script.
Examples of user data
Create a directory and upload files to it
Cloud-config
Bash script
An example script to create a directory and upload a file to it over the network:
#cloud-config
runcmd:
- mkdir /run/newdir
- [ wget, "http://example.com", -O, /run/newdir/index.html ]
An example script to create a directory and upload a file to it over the network:
#!/bin/sh
mkdir /run/newdir
wget http://example.com -O /run/newdir/index.html
Update repositories and install packages
Cloud-config
Bash script
Sample script to install pwgen and pastebinit:
#cloud-config
package_update: true
packages:
- pwgen
- pastebinit
An example script for installing docker:
#!/bin/sh
apt update
apt install docker
Place SSH keys on the server
Cloud-config
Bash script
Sample script:
#cloud-config
ssh_authorized_keys:
- ssh-rsa AAAAB3N…V7NZ user1@host
- ssh-rsa AAAAB3N…NtHw== user2@server
Sample script:
#!/bin/sh
echo "ssh-rsa AAAAB3N…V7NZ user1@host" >> /root/.ssh/authorized_keys
echo "sssh-rsa AAAAB3N…NtHw== user2@server" >> /root/.ssh/authorized_keys
Customize the configuration file
Cloud-config
Bash script
Sample script for the resolv.conf domain name 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
Sample script for the resolv.conf domain name resolver:
#!/bin/sh
cat <<EOF > /etc/resolv.conf
domain example.com
nameserver 4.4.4.4
nameserver 8.8.8.8
search foo.example.com bar.example.com
options rotate
options timeout:1
EOF