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.

hi
nobody try to manage MAAS with the API ???

@PouicPouic, plenty of people manage MAAS with the CLI, including me. for example, you can take a look at this tutorial, where I walk the CLI thru its paces.

i’m not sure if your question is related to the post above. is there a specific question i can answer for you?

I have moved on from using the MAAS CLI as it’s not portable enough. I would like to use the API https://maas.io/docs/api. The reason for moving on from using the CLI is that I need to install it on a server and that limits useability. The API provides a lot more mileage, You can write a python or some other language that makes calls to the API directly and your code is portable. The link I posted above could use more documentation on how to make calls to the API with the examples, some python code examples or shell scripts examples would help a lot.

I’m also looking into use the Terraform MAAS module https://registry.terraform.io/providers/suchpuppet/maas/3.1.3 ( not sure if this is associated with Ubuntu MAAS) but it’s got me going

Stormrider seems to be offline

hi

thanks for the answer .
but i would like to do it with ansible and URI call .

api documentationis not clear… i upset i need to work with a " cli" . and for automation i don t find really easy . to work with .

hi

i try to use API too, in order to manage machine( creation/update)
but i don t find the way to configure the network part od the new machine. below my json file a load on my API call

did you know how to definet FABRIC ans DHCP mode on a machine with a API CALL ?

thanks.

it sounds like there are some feature requests here, targeted toward the API. IIUC, you’ll want to explain the issues you’re having in more detail in the feature requests section of the forum, since that’s how these requests get picked up and noticed. obviously, we can’t respond to every feature request, but we do try, when we can work it into our roadmap.

i do it :