User data plays a pivotal role in the rapid initialization of cloud instances, facilitating the automatic configuration of instances upon boot-up. Whether through user data module, script commands or YAML-formatted cloud-config information, user data imbues instances with unique settings and software, transforming them from generic Ubuntu images into fully configured servers within moments. By leveraging cloud-init, instances gain their distinct personalities, as user data is seamlessly applied during the instance creation process, ensuring efficient and customized cloud computing experiences.
To register a new user data, follow these steps:
1. Navigate to Compute → User Data on the left navigation bar.
2. Click on Register a userdata in the top row:
3. Specify the following data in the popup window:
4. Click on OK to save and register the user data.
Once user data is registered, it can be assigned during the creation process of an instance like this:
1. Navigate to Compute → Instance on the left navigation bar.
2. Click on Add instance in the top row:
For more help and information on this topic, refer to our Creating Instances chapter.
3. During the creation process in the Advanced mode setting, you can select any stored user data from the list view. If the user data contains variables that were declared during registration, those values have to be specified like this:
4. Complete the creation process by specifying the remaining parameters and click on Launch instance to set up the new instance with user data successfully.
When inside the instance, you can access the user data through the virtual router, provided the user data service is enabled in the network offering. If you're using the DNS service of the virtual router, a designated hostname data-server directs you to a valid user data server. Alternatively, you may need to find the virtual router address through DHCP leases or other means. Take caution to check all routers if multiple networks are attached to an instance, as not all may have the user data service enabled.
You can access the user data by referring to the URL http://data-server./latest/user-data
using curl or other HTTP clients. Note that HTTP GET parameters are limited to a length of 2048 bytes. However, you can store larger user data by sending them in the body via HTTP POST instead of GET.
You can also fetch metadata in the same manner using the URL http://data-server./latest/{metadata type}
. Below is the list of all available metadata types:
service-offering
: A description of the instances service offering.availability-zone
: The zone name.local-ipv4
: The guest IP of the instance.local-hostname
: The hostname of the instance.public-ipv4
: The first public IP for the router.public-hostname
: This is the same as public-ipv4.instance-id
: The instance name of the instance.To delete a user data, follow these steps:
1. Navigate to Compute → User data on the left navigation bar.
2. Mark one or more key pairs from the list view.
3. Click on the Remove user data button in the top row:
4. Click on OK and the operation window will provide you with information and the status of the key removal process.
Our IaaS Cloud uses cloud-init to apply user data to our instances automatically. To get more information about the latest capabilities of user- and meta-data, refer to the cloud-init documentation.
For example, you can utilize a general cloud-init template to update all OS packages during the first launch. To do this, you need to:
1. Register the following user data in your IaaS Cloud:
base64 <<EOF
Content-Type: multipart/mixed; boundary="//"
MIME-Version: 1.0
--//
Content-Type: text/cloud-config; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment; filename="cloud-config.txt"
#cloud-config
# Upgrade the instance on first boot
# (ie run apt-get upgrade)
#
# Default: false
# Aliases: apt_upgrade
package_upgrade: true
EOF
2. Assign the user data to a new instance and launch it:
For a more hands-on tutorial on how to use user data, navigate to our Working with User Data.