Configuring your instance during boot with a user data file


When using the OpenStack command line to create an instance, you can provide a user data file during boot to configure your instance. This allows you to set system variables or install packages during boot time.

This is possible due to cloud-init which is installed on several Linux systems by default. This description is from the cloud-init website:

"cloud-init is the Ubuntu package that handles early initialization of a cloud instance. It is installed in the Ubuntu Cloud Images and also in the official Ubuntu images available on EC2."

What is a user data file?

A user data file is a text file that you can include when running the openstack server create command. This file is used to customize your instance during boot. View the following page for a list of 'User Data Input Formats'.

You can place data in a local file and pass it through using the --user-data <user-data-file> parameter at instance creation. This shows how to pass a file named to an Ubuntu-16.04 image.

[user@localhost]$ openstack server create --flavor 300 \
                        --image 23f77038-51dc-40f3-8714-50612b0efb24 \
                        --key-name myKey \
                        --security-group 29afef85-b89f-43a0-babf-6a5bb5cc7bed \
                        --user-data \

Example shell script

This simple example shows how to install pip3 during instance creation.


# Example script to run at boot
# This installs pip3
apt update
apt -y install python3-pip
pip3 install --upgrade pip

Now when you log into the instance, pip3 is already installed.

Did this article answer your questions?

Article last updated PST.

Still not finding what you're looking for?