• Improve this Doc

    Show / Hide Table of Contents

    How to configure an OpenStack instance using cloud-config

    Overview

    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.

    Use cases

    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_keys so they can log in
    • Setting up ephemeral mount points
    • Configuring network devices
    • Running config scripts at startup

    Example

    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.

    1. Create a new text file called user-data.txt.

    2. 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
      
      Note

      You must include the #cloud-config line at the top of the file.

    3. Boot an instance using the CLI, adding --user-data user-data.txt to the end of the boot command.

    4. 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.

    Next steps

    You can find documentation for cloud-config at the following location:

    https://cloudinit.readthedocs.io/en/latest/topics/examples.html

    Feedback

    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 feedback@ukcloud.com.

    ☀
    ☾
    Generated by DocFX
    Back to top
    © UKCloud Ltd, 2022. All Rights Reserved.
    Privacy Policy. Terms of Use. Contribute.

    The UKCloud Knowledge Centre uses cookies to ensure that we give you the best experience on our website. If you continue we assume that you consent to receive all cookies on this website.