Using MAAS-CLI to deploy machines

Hello,

Has anyone used the maas-cli in MAAS 3.0 to deploy servers?

@cmills, yeah, i do it all the time. i’m assuming you’re not just talking about deployment, but commissioning, etc --> deployment?

either way, check my website for a walkthru. it’s an older version, but same commands apply, AFAIK.

1 Like

Hello Billwear, I just a few moments ago use the following command

maas-cli deploy focal social-mink --user-data cloud_config_ubuntu.cfg

works perfectly, now I need to figure out how to set the interface to use DHCP instead of “Assign”

This is the magic from what we call our provisioning script, which we run after commissioning, and before deployment. We try to do as much as possible in scripts and CLI, to avoid slower web UI use.

SYSTEM_DESC=$(maas "$MAAS_USER" nodes read id="$SYSTEM_ID")
BOOT_INTERFACE_ID=$(echo "$SYSTEM_DESC" | jq -r '. [] .boot_interface .id')
BRIDGE_CREATION=$(maas "$MAAS_USER" interfaces create-bridge "$SYSTEM_ID" name="admin" parent="$BOOT_INTERFACE_ID")
BRIDGE_ID=$(echo "$BRIDGE_CREATION" | jq '.id')
DHCP_ENABLED=$(maas "$MAAS_USER" interface link-subnet "$SYSTEM_ID" "$BRIDGE_ID" subnet=$ADMIN_SUBNET mode=Auto)

That sets it to Auto assign. For DHCP, just change Auto to DHCP.

2 Likes

@cmills, see @gregoryo2017’s post above. he lays it out for you. (many thanks @gregoryo2017!)

Hello @gregoryo2017

What you mentioned looks interesting especially this section
DHCP_ENABLED=$(maas “$MAAS_USER” interface link-subnet “$SYSTEM_ID” “$BRIDGE_ID” subnet=$ADMIN_SUBNET mode=Auto)

I’m just learning how to use jq.

Thanks for the reply @gregoryo2017

@gregoryo2017,

You mentioned “maas” is that an alias or short for another command. I’m using maas-cli from a remote server. when I do maas-cli help or even maas-cli help commands. I don’t see any option that has an argument that reference Interface?

We run maas CLI commands from a maas-rackd server, but I wonder if it can be installed elsewhere and authenticate against the server.
I don’t really know about maas-cli, although I find this a bit confusing:

$ maas-cli

Command 'maas-cli' not found, but can be installed with:

snap install maas-cli
Please ask your administrator.

$ dpkg -l | grep maas-cli
ii  maas-cli                               1:3.0.0-10029-g.986ea3e45-0ubuntu1~20.04.1 all          MAAS client and command-line interface
ii  python3-maas-client                    1:3.0.0-10029-g.986ea3e45-0ubuntu1~20.04.1 all          MAAS python API client (Python 3)
$ command -v maas
/usr/bin/maas
$ cat /usr/bin/maas
#!/usr/bin/python3
# EASY-INSTALL-ENTRY-SCRIPT: 'maas==3.0.0','console_scripts','maas'
__requires__ = 'maas==3.0.0'
import re
import sys
from pkg_resources import load_entry_point

if __name__ == '__main__':
    sys.argv[0] = re.sub(r'(-script\.pyw?|\.exe)?$', '', sys.argv[0])
    sys.exit(
        load_entry_point('maas==3.0.0', 'console_scripts', 'maas')()
    )

Although looking again, it looks like it might be the same thing:

$ dpkg -L maas-cli
/.
/usr
/usr/bin
/usr/bin/maas
...

As for remote login and use, this suggests that’s how we use it, especially since the FQDN it shows is our maas-regiond controller, and as I mentioned we run commands from the maas-rackd controller.

$ maas
usage: maas [-h] COMMAND ...

optional arguments:
  -h, --help  show this help message and exit

drill down:
  COMMAND
    login     Log in to a remote API, and remember its description and credentials.
    logout    Log out of a remote API, purging any stored credentials.
    list      List remote APIs that have been logged-in to.
    refresh   Refresh the API descriptions of all profiles.
    <my_user> Interact with http://maas.FQDN:5240/MAAS/api/2.0/

https://maas.io/

too few arguments

Hello @gregoryo2017 cc @billwear

$ sudo snap list maas
Name Version Rev Tracking Publisher Notes
maas 3.0.0-10029-g.986ea3e45 15003 3.0/stable canonical✓ -

sudo snap list maas-cli
Name Version Rev Tracking Publisher Notes
maas-cli 0.6.5 13 latest/stable canonical✓ -

Two different applications, maas-cli is installed from a seperate server not related to the MAAS environment.

Well that’s a lovely tangle. But wherever possible we treat snap like the yet-another-homegrown-packaging-system that it is, and don’t use it.