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.
- Write a file that includes your cloud-init userdata (e.g. example.yaml)
#cloud-config
packages:
- <package1>
- <package2>
- Convert it to base64
user_data=$(base64 example.yaml)
- 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.
- Write a shell script you would like to execute (e.g. sample.sh).
#!/bin/sh
(
echo ============== $(date) =================
echo "test" > ~/sample.file
) | tee /my.log
- Convert it to base64.
user_data=$(base64 -w 0 sample.sh)
- Pass it to MAAS when deploying a machine
maas maas-user machine deploy asdfe3 user_data=$user_data