Jump toUpdate content

Using cloud-init with Scaleway API and CLI

Reviewed on 26 May 2021Published on 26 May 2021

Cloud-init is a package that contains utilities for early initialization of cloud instances. It enables automatic configuration of cloud instances as it boots into the cloud, turning it from a generic Ubuntu image into a configured server in a few seconds, quickly and easily

The cloud-init program that is available on recent distributions (Ubuntu, Fedora, Debian) is able to consume and execute data from the user-data field of the Scaleway service. This process behaves differently depending on the format of the information it finds. One of the most popular formats for scripts within user-data is the cloud-config file format.

Cloud-config files are special scripts designed to be run by the cloud-init process. These are generally used for initial configuration on the very first boot of a server.

Requirements:

Provisioning your Instance with Cloud-Init

You can give provisioning instructions to cloud-init using the cloud-init key of the user_data facility.

For user_data to be effective, it has to be added prior to the creation of the instance since cloud-init gets activated early in the first phases of the boot process.

  • Server ID refers to the unique identification string of your server. It will be displayed when you create your server. You can also recover it from the list of your servers, by typing scw ps.
  1. Create your Instance by specifying the path to your cloud-init configuration file.

    $ scw instance server create image=ubuntu_focal name=myinstance cloud-init=@/path/to/cloud-config-file
    Note:

    @/path/to/cloud-config-file is the path of your Cloud-Init configuration file. Edit it towards your requirements.

  2. Start your Instance

    $ scw start {server Id}

Cloud-Init CLI (Command Line Interface)

The command line documentation is accessible on any cloud-init installed system.

% cloud-init --helpusage: cloud-init [-h] [--version] [--file FILES]
                  [--debug] [--force]                  {init,modules,single,dhclient-hook,features,analyze,devel,collect-logs,clean,status}                  ...
optional arguments:  -h, --help            show this help message and exit  --version, -v         show program's version number and exit  --file FILES, -f FILES                        additional yaml configuration files to use  --debug, -d           show additional pre-action logging (default: False)  --force               force running even if no datasource is found (use at                        your own risk)
Subcommands:  {init,modules,single,dhclient-hook,features,analyze,devel,collect-logs,clean,status}    init                initializes cloud-init and performs initial modules    modules             activates modules using a given configuration key    single              run a single module    dhclient-hook       run the dhclient hookto record network info    features            list defined features    analyze             Devel tool: Analyze cloud-init logs and data    devel               Run development tools    collect-logs        Collect and tar all cloud-init debug info    clean               Remove logs and artifacts so cloud-init can re-run.    status              Report cloud-init status or wait on completion.

For detailed information on Cloud-init, refer to the official cloud-init documentation.