How to configure an OpenStack instance using cloud-config
When you boot an instance in OpenStack you can pass configuration to the instance as cloud-config (sometimes called user-data). This enables you to quickly and easily make configuration changes at boot time.
The following list provides some examples of how you can use cloud-config to configure an instance:
- Setting a default locale
- Setting an instance hostname
- Generating instance SSH private keys
- Adding SSH keys to a user's
.ssh/authorized_keysso they can log in
- Setting up ephemeral mount points
- Configuring network devices
- Running config scripts at startup
You can deploy cloud-config via the command line or via the OpenStack Horizon GUI. In this guide, we use the CLI, but you can use the same script via the GUI by pasting it into the Configuration tab.
As an example, let's boot an instance and run some arbitrary commands at boot time.
Create a new text file called
Add the following to the new file.
#cloud-config runcmd: - mkdir -pv /root/cloud-config-test - touch /root/cloud-config-test/boottest - echo "boot instance test" >> /root/cloud-config-test/boottest
You must include the
#cloud-configline at the top of the file.
Boot an instance using the CLI, adding
--user-data user-data.txtto the end of the boot command.
When the instance has booted, log into the instance, switch to root and look in the directory. You will see the new file, and it will contain
boot instance test.
This is a very simple example of what you can do with cloud-config, but you can see from this simple example that you can easily start to build fairly complicated setup scripts.
You can find documentation for cloud-config at the following location:
If you find a problem with this article, click Improve this Doc to make the change yourself or raise an issue in GitHub. If you have an idea for how we could improve any of our services, send an email to email@example.com.