Are there examples of custom installation scripts?

Solution 1:

Depending on which installer you are using, MAAS provides different mechanisms to customize an installation. This answer assumes you are using the curtin installer (also known as fast-path installer) which became the default in MAAS 1.7.

MAAS uses cloud-init as part of its installation process. There are multiple ways to customize cloud-init behaviour, the easiest being simply providing a User-Data Script, which cloud-init executes during first boot, after the operating system installation is complete.

In MAAS, this can be accomplished by providing the user_data argument to the node start CLI command. The format of that command is:

maas <user> node start <node uuid> user_data=<script> distro_series=<name>

where <script> is actually a base64-encoded string. For a concrete example, assuming you would like to run a script called addkey.sh which prints some output to the installation console, imports an SSH key from Launchpad for the user ubuntu, and logs the results to a logfile:

#!/bin/sh
(
echo ======== Hi World ======================
echo ============== $(date) =================
ssh-import-id user
) | tee /my.log

you could issue the following commands:

$ script=$(base64 addkey.sh)
$ maas myuser node start node-79b67e82-d25c-11e4-a333-00163eca91de \
  user_data=$script distro_series=trusty

which if successful should return (after a while) output in the following format:

Success.
Machine-readable output follows:
{
    "status": 6, 
    "macaddress_set": [
        {
...

Now this runs that script after deployment of one specific node. If you'd like to have commands set up so they run on any node which is installed through MAAS, you can add the commands to be run as part of the late_commands stanza in the /etc/maas/preseeds/curtin_userdata file. For a more complex example which uses this mechanism to set up two VLANs on a network interface, see http://astokes.org/customizing-fastpath-curtin-installations/.

Note that Curtin is currently mostly undocumented; there is however an overview file that describes some of the detail of its operation.

Keep in mind this mechanism is not to be confused with a comissioning script, run during the commissioning phase, and which in the MAAS node life-cycle comes before installation. Commissioning is generally used for administrative tasks that are meant to not directly affect installation; examples would be:

  • firmware updating
  • sanity testing of key hardware components
  • burn-in

Solution 2:

It should be noted that the commands here are for the 1.0 API. In 2.0 and upwards, the command is:

maas <profile> machine deploy <system_id> user_data=<base64-encoded-userdata>