Cloud-Init and User-Data
User Data is a way to automatically provision your machine with additional software or settings. You can provide a set of commands (ie. a script) or enter cloud-config information as YAML. It is important to understand that the User Data provided will be used only when the machine is created.
Adding User Data
When you’re creating a new instance, the wizard lets you enter User Data at the bottom of the form.
You can find everything that can be done with User Data and Cloud-Init in the documentation
htop on an Ubuntu instance using Apt after having
upgraded all packages on an Debian/Ubuntu system.
Add the following to the
User Data field to install the
#cloud-config runcmd: - apt-get --yes upgrade - apt-get --yes install screen htop
Note: Cloud-Init has pre-built directives for many items. Therefore, the previous scripts launched as command lines could be achieved with:
#cloud-config package_upgrade: true packages: - screen - htop
Example: cloud-config YAML
Let’s set our locale to en_US.UTF-8 using cloud-config YAML. Add the following YAML in the User Data:
#cloud-config locale: "en_US.UTF-8"
Example: installing Wordpress
See our Wordpress tutorial
Querying the user data and meta data from the instance
User Data and
Meta Data can be retrieved from an instance to
integrate in scripts for example or configuration management tools.
- User Data (the cloud-config contents)
- Meta Data, such as instance size or IP address
curl http://metadata.exoscale.com/latest/meta-data curl http://metadata.exoscale.com/latest/meta-data/public-ipv4