MAAS Show and Tell: Commissioning Scripts; Discourse Automation Tools

Welcome to another MAAS show and tell! Today, Lee is talking at length about commissioning scripts, and Bill is giving a quick peek at some discourse automation he’s working on for future projects. Enjoy!

MAAS show and tell for 25 Jun 2020.

The script’s shown in Lee’s presentation can be seen below. More information about writing custom commissioning scripts can be found at in the MAAS docs.

basic.sh

#!/bin/bash
# --- Start MAAS 1.0 script metadata ---
# name: basic
# title: This is a basic commissioning script
# description: This is a very basic commissioning script used for demoing
# # Scripts can be run by tag. Some tags have special meaning to MAAS.
# # "noauto" means don't automatically run this commissioning script.
# tags: [basic, demo, noauto]
# script_type: commissioning
# # timeout can be defined in seconds or using HH:MM:SS format
# timeout: 5
# # Run this script in parallel along with other scripts marked parallel.
# parallel: any
# --- End MAAS 1.0 script metadata ---

echo "Hello stdout"
echo "Hello stderr" >&2

ruby.rb

#!/usr/bin/env ruby
# --- Start MAAS 1.0 script metadata ---
# name: ruby
# title: This is a Ruby script
# description: This is a commissioning script written in Ruby.
# tags: [install, demo]
# script_type: commissioning
# timeout: 5
# parallel: any
# # packages are installed before the script runs. This allows a script to
# # be written with any language!
# packages: {apt: ruby}
# --- End MAAS 1.0 script metadata ---

puts "Hello Ruby!"

packages.sh

#!/bin/bash
# --- Start MAAS 1.0 script metadata ---
# name: packages
# title: This script installs things!
# description: This script shows automatic installation of various package types.
# tags: [install, demo]
# script_type: commissioning
# timeout: 5
# parallel: any
# packages:
#   apt: [screenfetch, jq]
#   # Snap's can also be installed. This can be a list of Snap name's or a list of
#   # dictionaries containing a Snap name, the Snap channel, and revision.
#   snap:
#     - name: maas-cli
#       channel: edge
#   # URL's can also be specified. Archives are automatically extracted to $DOWNLOAD_PATH.
#   # Debian packages will be automatically installed along with required dependencies.
#   # Snap's may also be specified.
#   url: https://releases.hashicorp.com/packer/1.6.0/packer_1.6.0_linux_amd64.zip
# --- End MAAS 1.0 script metadata ---

screenfetch -N
jq --version
/snap/bin/maas-cli help
chmod +x $DOWNLOAD_PATH/packer
$DOWNLOAD_PATH/packer --help

update_firmware.sh

#!/bin/bash
# --- Start MAAS 1.0 script metadata ---
# name: demo_update_firmware
# title: Demo of updating firmware
# description: This is script simulates updating firmware.
# # The update_firmware tag is required to use the "Update firmware" option in the UI.
# tags: update_firmware
# script_type: commissioning
# timeout: 00:05:00
# # When selected, this script will only run on hardware matching the below string.
# for_hardware: system_version:pc-q35-4.0
# # may_reboot lets MAAS know the script may reboot the system. This ensures the
# # script isn't marked as a failure due to a timeout when rebooting.
# may_reboot: True
# --- End MAAS 1.0 script metadata ---

# The HAS_STARTED environment variables defines if the script has already run. When
# a script reboots it will rerun the script.
if [ "$HAS_STARTED" == "False" ]; then
    echo "This is being run on a system with version pc-q35-4.0!"
    echo "The script has $RUNTIME seconds to run, not including reboot time."
    reboot
else
    echo "Reboot complete!"
fi

configure_hpa.sh

#!/bin/bash
# --- Start MAAS 1.0 script metadata ---
# name: config_hpa
# title: This is commissioning script configures an HPA
# description: This script configures an HPA
# # The configure_hpa tag is required to use the "Configure HBA" option in the UI.
# tags: configure_hpa
# script_type: commissioning
# # PCI ID's may also be used to identify when the script should run.
# for_hardware: pci:1af4:1042
# timeout: 00:05:100  
# # After all commissioning scripts have run this will trigger the built in commissioning
# # scripts to rerun.
# recommission: True
# --- End MAAS 1.0 script metadata ---

echo "Reconfiguring HPA..."

failure.sh

#!/bin/bash
# --- Start MAAS 1.0 script metadata ---
# name: failure
# title: This script will fail
# description: This script will fail but only when run on a system with an Intel controller.
# tags: demo
# script_type: commissioning
# timeout: 5
# # Intel C610/X99 Controller
# for_hardware: pci:8086:8d06
# --- End MAAS 1.0 script metadata ---

# Any script which returns a non-zero return code will be marked as failure.
exit 1

Bill’s discourse automation tools are available in his github.

Please feel free to leave comments or questions on this post.