Using cloud-init with Scaleway API and CLI
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.
You may need certain IAM permissions to carry out some actions described on this page. This means:
- you are the Owner of the Scaleway Organization in which the actions will be carried out, or
- you are an IAM user of the Organization, with a policy granting you the necessary permission sets
- You have a Scaleway account
- You have configured your API keys
- You have downloaded the latest version of the Scaleway CLI tools, directly from GitHub.
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 instance server list
.
-
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-fileNote:@/path/to/cloud-config-file
is the path of your Cloud-Init configuration file. Edit it towards your requirements. -
Start your Instance
scw start {server Id}Since version 2.3.1 of the Scaleway CLI a shorter command is available:
scw instance server create image=ubuntu_focal name=myinstance cloud-init=@/path/to/cloud-config-file
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.