Customizing MAAS deployments with cloud-init


#1

Customizing MAAS deployments with cloud-init provides users a standard way to customize deployments, which is similar to any cloud environment out there. Using this path provides a good way to customize deployments across all Operating Systems that support cloud-init, and it is done after the machine has booted into the installed OS for the first time (after it is ‘Deployed’ in MAAS).

But how is this done? Well it’s quite easy. The only thing you need to do is to pass cloud-init user-data to a machine when deploying it over the API.

For example:

maas <user> machine deploy <system_id> user_data=<base64 encoded user-data>

Examples

Customizing with cloud-init user data (Works for Ubuntu, CentOS, RHEL)

In this example we are going to customize the deployment by using cloud-init userdata. This means that the user will describe cloud-init configuration that will then be interpreted by cloud-init and executed upon on first boot.

  1. Write a file that includes your cloud-init userdata (e.g. example.yaml)
#cloud-config
packages:
  - <package1>
  - <package2>
  1. Convert it to base64
user_data=$(base64 example.yaml)
  1. Pass the user_data on deploy
maas maas-user machine deploy asdfe3 user_data=$user_data

Customizing with a shell script (Works for Ubuntu, CentOS, RHEL)

Cloud-init can also directly execute shell scripts.

  1. Write a shell script you would like to execute (e.g. sample.sh).
#!/bin/sh
(
echo ============== $(date) =================
echo "test" > ~/sample.file
) | tee /my.log
  1. Convert it to base64.
user_data=$(base64 sample.sh)
  1. Pass it to MAAS when deploying a machine
maas maas-user machine deploy asdfe3 user_data=$user_data
NOTE: You can also pass user_data for Windows deployments but that follow cloud-baseinit convention.

Source routing on server
#2

Is it possible to add cloud-init scripts for commissioning in the GUI? I tried and it complained the script must start with a shebang.


#3

Commissioning scripts are not really cloud-init user-data. Commissioning scripts are just simply any normal script, which can be python, shell, etc.

More information on commissioning/testing scripts and all the fancy things you can do with them are described here: https://docs.maas.io/2.5/en/nodes-scripts