Skip to content

Commit

Permalink
doc: add some API instructions for cloud-init
Browse files Browse the repository at this point in the history
Signed-off-by: Ruth Fuchss <[email protected]>
  • Loading branch information
ru-fu committed Feb 20, 2024
1 parent d56f233 commit be513e9
Showing 1 changed file with 30 additions and 1 deletion.
31 changes: 30 additions & 1 deletion doc/cloud-init.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ To configure `cloud-init` for an instance, add the corresponding configuration o

When configuring `cloud-init` directly for an instance, keep in mind that `cloud-init` runs only on the first start of the instance.
That means that you must configure `cloud-init` before you start the instance.
To do so, create the instance with [`lxc init`](lxc_init.md) instead of [`lxc launch`](lxc_launch.md), and then start it after completing the configuration.
If you are using the CLI client, create the instance with [`lxc init`](lxc_init.md) instead of [`lxc launch`](lxc_launch.md), and then start it after completing the configuration.

### YAML format for `cloud-init` configuration

Expand All @@ -92,6 +92,35 @@ config:
See {ref}`How to validate user data <cloud-init:check_user_data_cloud_config>` for information on how to check whether the syntax is correct.
```

### Configure `cloud-init` through the API

If you are using the API to configure your instance, provide the `cloud-init` configuration as a string with escaped newline characters.

For example:

lxc query --request PATCH /1.0/instances/<instance_name> --data '{
"config": {
"cloud-init.user-data": "#cloud-config\npackage_upgrade: true\npackages:\n - package1\n - package2"
}
}'

Alternatively, to avoid mistakes, write the configuration to a file and include that in your request.
For example, create `cloud-init.txt` with the following content:

#cloud-config
package_upgrade: true
packages:
- package1
- package2

Then send the following request:

lxc query --request PATCH /1.0/instances/<instance_name> --data '{
"config": {
"cloud-init.user-data": "'"$(awk -v ORS='\\n' '1' cloud-init.txt)"'"
}
}'

## How to check the `cloud-init` status

`cloud-init` runs automatically on the first start of an instance.
Expand Down

0 comments on commit be513e9

Please sign in to comment.