MAAS CLI

The MAAS CLI can do everything that the web UI can do, and more. The CLI uses the maas command exclusively which, in turn, connects to the API. This page explains what is needed to get started with the CLI.

Note that this article does not provide complete coverage of the MAAS CLI. For an exhaustive treatment, you may want to check the API documentation. Also note that this page represents user-entered values as uppercase variables preceded with the ‘$’ character (e.g. $PROFILE and $EMAIL_ADDRESS). You should replace these placeholders with actual values.

Six questions you may have:

  1. How do I access the MAAS CLI?
  2. How do I create an administrator account?
  3. How do I complete the required login?
  4. How do I get help via the CLI?
  5. How do I log out?
  6. What are some the next steps I can take with the CLI?

The maas command

You can obtain the maas command via the maas-cli Ubuntu package installed on every region API server and rack controller. To manage MAAS at the CLI level from a remote workstation, you will need to install this package:

sudo apt install maas-cli

Create an administrator

MAAS requires an initial administrator, sometimes called a MAAS “superuser”. When you access the web UI for the first time, you will be prompted to create this user:

sudo maas createadmin --username=$PROFILE --email=$EMAIL_ADDRESS

You can create extra administrators in the same way. See MAAS CLI - common tasks for instructions on creating regular users with the CLI.

Log in (required)

To use the CLI you must first log in to the API server (region controller).

You will need the API key that MAAS generated when creating your MAAS account. To obtain it, run this command on the region controller (i.e. wherever you installed the ‘maas-region-controller’ package):

sudo maas-region apikey --username=$PROFILE > $API_KEY_FILE

You can obtain a user’s API key from the web interface. Click on ‘username’ in the top right corner, and select ‘Account’.

Log in. MAAS will prompt you for the API key:

maas login $PROFILE $MAAS_URL

For example, to log in with the account whose username is ‘admin’ and where the region controller is on the localhost:

maas login admin http://localhost:5240/MAAS/api/2.0

To log in by referring to the API key file created earlier:

maas login $PROFILE $MAAS_URL - < $API_KEY_FILE

A handy shell script, say maas-login.sh, is provided:

#!/bin/sh

# Change these 3 values as required 
PROFILE=admin
API_KEY_FILE=/home/ubuntu/tmp/api_key
API_SERVER=localhost

MAAS_URL=http://$API_SERVER/MAAS/api/2.0

maas login $PROFILE $MAAS_URL - < $API_KEY_FILE

Get help

MAAS has a thorough built-in help reference, which you can access in stages to understand how to build commands.

The maas command accepts the -h or --help argument after every keyword and will display results with increasing detail.

For example, suppose you were interested in tag management but didn’t know where to start. You might try this:

maas $PROFILE --help

At this stage, you’ll see all available MAAS commands, including the tag and tags commands, along with a brief explanation of what each command does. To see what the tag and tags commands have to offer, try:

maas $PROFILE tag --help

And:

maas $PROFILE tags --help

Suppose you want to create a new rudimentary tag. Find the next level of help like this:

maas admin tags create --help

In this way, you can discover all that the MAAS CLI has to offer.

Log out

Once you finish with the CLI, you can log out from the given profile, flushing the stored credentials.

maas logout $PROFILE

Next steps

The following five categories are now available to be explored:

  1. Common tasks
  2. Kernel management
  3. Image management
  4. Advanced tasks
  5. Composable hardware
Common CLI tasks
CLI image management
Python API client
CLI DHCP snippet management
CLI interface management
Custom machine setup
Interactive search
IPv6 addressing
About MAAS
About MAAS (CLI)
Custom machine setup (CLI)
Installation and configuration checklist (UI)
Interactive search (CLI)
Installation and configuration checklist (CLI)
Ipv6 addressing (CLI)
Ipv6 addressing (UI)
Interactive search (UI)
The CLI cookbook
Python API client (CLI)
Python API client (UI)
Enabling MAAS 2.7 (packages/CLI)
User accounts (UI)
Resource pools (snap/2.9/CLI)
Resource pools (deb/2.7/CLI)
Resource pools (deb/2.8/CLI)
Resource pools (snap/2.8/CLI)
Resource pools (snap/2.7/CLI)
Resource pools (deb/2.9/CLI)
MAAS tags (deb/2.8/CLI)
MAAS tags (snap/2.8/CLI)
MAAS tags (snap/2.9/CLI)
MAAS tags (deb/2.7/CLI)
MAAS tags (snap/2.7/CLI)
MAAS tags (deb/2.9/CLI)
Enabling MAAS 2.8 (packages/CLI)
Enabling MAAS 2.7 (snap/CLI)
Enabling MAAS 2.7 (snap/UI)
Enabling MAAS 2.7 (packages/UI)
Enabling MAAS 2.8 (snap/CLI)
Enabling MAAS 2.8 (snap/UI)
Enabling MAAS 2.8 (packages/UI)
CLI advanced tasks (snap/2.7/CLI)
CLI advanced tasks (snap/2.9/CLI)
CLI advanced tasks (snap/2.7/UI)
CLI advanced tasks (snap/2.8/CLI)
CLI advanced tasks (snap/2.8/UI)
CLI advanced tasks (snap/2.9/UI)
CLI advanced tasks (deb/2.7/CLI)
CLI advanced tasks (deb/2.7/UI)
CLI commissioning and hardware testing scripts (snap/2.8/CLI)
CLI commissioning and hardware testing scripts (deb/2.9/CLI)
CLI composable hardware (snap/2.7/UI)
CLI composable hardware (deb/2.8/UI)
CLI advanced tasks (deb/2.8/CLI)
CLI advanced tasks (deb/2.8/UI)
CLI advanced tasks (deb/2.9/CLI)
CLI advanced tasks (deb/2.9/UI)
CLI commissioning and hardware testing scripts (snap/2.7/CLI)
CLI commissioning and hardware testing scripts (snap/2.9/CLI)
CLI commissioning and hardware testing scripts (deb/2.7/UI)
CLI commissioning and hardware testing scripts (deb/2.8/UI)
CLI composable hardware (snap/2.8/UI)
CLI composable hardware (snap/2.9/CLI)
CLI commissioning and hardware testing scripts (snap/2.7/UI)
CLI commissioning and hardware testing scripts (snap/2.8/UI)
CLI commissioning and hardware testing scripts (snap/2.9/UI)
CLI commissioning and hardware testing scripts (deb/2.7/CLI)
CLI commissioning and hardware testing scripts (deb/2.8/CLI)
CLI commissioning and hardware testing scripts (deb/2.9/UI)
CLI composable hardware (snap/2.7/CLI)
CLI composable hardware (snap/2.8/CLI)
CLI composable hardware (deb/2.7/CLI)
CLI composable hardware (snap/2.9/UI)
CLI composable hardware (deb/2.7/UI)
CLI composable hardware (deb/2.8/CLI)
CLI composable hardware (deb/2.9/CLI)
CLI composable hardware (deb/2.9/UI)
CLI DHCP snippet management (snap/2.7/CLI)
CLI DHCP snippet management (snap/2.8/CLI)
CLI DHCP snippet management (snap/2.9/CLI)
CLI DHCP snippet management (snap/2.9/UI)
CLI DHCP snippet management (deb/2.8/CLI)
CLI DHCP snippet management (snap/2.7/UI)
CLI DHCP snippet management (snap/2.8/UI)
CLI DHCP snippet management (deb/2.7/CLI)
CLI DHCP snippet management (deb/2.7/UI)
CLI DHCP snippet management(deb/2.9/CLI)
CLI image management (snap/2.7/UI)
CLI DHCP snippet management (deb/2.8/UI)
CLI DHCP snippet management (deb/2.9/UI)
CLI image management (snap/2.7/CLI)
CLI image management (snap/2.9/CLI)
CLI image management (deb/2.7/CLI)
CLI image management (deb/2.7/UI)
CLI image management (snap/2.8/CLI)
CLI image management (snap/2.8/UI)
CLI image management (deb/2.8/UI)
CLI image management (deb/2.9/CLI)
CLI interface management (snap/2.7/CLI)
CLI image management (snap/2.9/UI)
CLI image management (deb/2.8/CLI)
CLI interface management (snap/2.9/UI)
CLI interface management (deb/2.7/UI)
CLI interface management (deb/2.9/UI)
CLI image management (deb/2.9/UI)
CLI interface management (snap/2.7/UI)
CLI interface management (snap/2.8/CLI)
CLI interface management (snap/2.9/CLI)
CLI kernel management (snap/2.7/CLI)
CLI interface management (snap/2.8/UI)
CLI interface management (deb/2.7/CLI)
CLI interface management (deb/2.8/CLI)
CLI interface management (deb/2.8/UI)
CLI interface management (deb/2.9/CLI)
CLI kernel management (snap/2.7/UI)
CLI kernel management (snap/2.9/UI)
CLI resource pool management (snap/2.7/CLI)
CLI resource pool management (snap/2.7/UI)
CLI resource pool management (snap/2.8/UI)
CLI kernel management (snap/2.8/UI)
CLI kernel management (deb/2.7/UI)
CLI kernel management (deb/2.8/CLI)
CLI kernel management (snap/2.8/CLI)
CLI kernel management (snap/2.9/CLI)
CLI kernel management (deb/2.7/CLI)
CLI kernel management (deb/2.8/UI)
CLI kernel management (deb/2.9/CLI)
CLI resource pool management (snap/2.9/CLI)
CLI kernel management (deb/2.9/UI)
CLI resource pool management (snap/2.8/CLI)
CLI resource pool management (snap/2.9/UI)
CLI resource pool management (deb/2.7/CLI)
CLI resource pool management (deb/2.7/UI)
CLI resource pool management (deb/2.8/CLI)
Select and import images (deb/2.8/CLI)
Select and import images (deb/2.7/CLI)
Select and import images (snap/2.7/CLI)
Select and import images (snap/2.8/CLI)
Select and import images (deb/2.9/CLI)
Select and import images (snap/2.9/CLI)
Common CLI tasks (snap/2.7/CLI)
Common CLI tasks (snap/2.7/UI)
Common CLI tasks (deb/2.9/CLI)
Common CLI tasks (snap/2.8/CLI)
Common CLI tasks (snap/2.9/CLI)
Common CLI tasks (snap/2.9/UI)
Common CLI tasks (snap/2.8/UI)
Common CLI tasks (deb/2.7/CLI)
Common CLI tasks (deb/2.9/UI)
Common CLI tasks (deb/2.7/UI)
Common CLI tasks (deb/2.8/CLI)
Common CLI tasks (deb/2.8/UI)
Enabling MAAS (snap/2.7/CLI)
Enabling MAAS (snap/2.7/UI)
Enabling MAAS (snap/2.8/CLI)
Enabling MAAS (snap/2.8/UI)
Enabling MAAS (deb/2.7/CLI)
Enabling MAAS (snap/2.9/CLI)
Enabling MAAS (snap/2.9/UI)
Enabling MAAS (deb/2.9/CLI)
Enabling MAAS (deb/2.8/CLI)
Enabling MAAS (deb/2.7/UI)
Enabling MAAS (deb/2.9/UI)
Enabling MAAS (deb/2.8/UI)
Interactive search (snap/2.7/UI)
Interactive search (snap/2.8/UI)
Interactive search (snap/2.9/CLI)
Interactive search (snap/2.8/CLI)
Interactive search (snap/2.9/UI)
Interactive search (snap/2.7/CLI)
Interactive search (deb/2.7/UI)
Interactive search (deb/2.8/UI)
Interactive search (deb/2.9/CLI)
Interactive search (deb/2.7/CLI)
Interactive search (deb/2.8/CLI)
Interactive search (deb/2.9/UI)
IPv6 addressing (snap/2.7/UI)
IPv6 addressing (snap/2.8/UI)
IPv6 addressing (snap/2.9/CLI)
IPv6 addressing (deb/2.7/UI)
IPv6 addressing (deb/2.9/CLI)
IPv6 addressing (deb/2.9/UI)
IPv6 addressing (snap/2.7/CLI)
IPv6 addressing (snap/2.9/UI)
IPv6 addressing (deb/2.8/CLI)
IPv6 addressing (snap/2.8/CLI)
IPv6 addressing (deb/2.7/CLI)
IPv6 addressing (deb/2.8/UI)
MAAS CLI (deb/2.7/CLI)
MAAS CLI (deb/2.8/UI)
MAAS CLI (snap/2.8/CLI)
MAAS CLI (snap/2.7/CLI)
MAAS CLI (snap/2.7/UI)
MAAS CLI (snap/2.8/UI)
MAAS CLI (snap/2.9/CLI)
MAAS CLI (snap/2.9/UI)
MAAS CLI (deb/2.7/UI)
MAAS CLI (deb/2.8/CLI)
MAAS CLI (deb/2.9/CLI)
MAAS CLI (deb/2.9/UI)
MAAS Documentation (snap/2.8/UI)
MAAS Documentation
CLI tag management (2.7)
About MAAS (deb/2.7/CLI)
CLI resource pool management (2.8)
CLI resource pool management (2.7)
CLI tag management (2.8)
CLI tag management (2.9)
CLI resource pool management (2.9)
About MAAS (deb/2.9/CLI)
About MAAS (deb/2.8/CLI)
About MAAS (snap/2.9/CLI)
About MAAS (snap/2.7/CLI)
About MAAS (snap/2.8/CLI)
Python API client (snap/2.7/UI)
Python API client (deb/2.9/CLI)
Python API client (snap/2.7/CLI)
Python API client (snap/2.8/CLI)
Python API client (snap/2.8/UI)
Python API client (deb/2.7/CLI)
Python API client (deb/2.7/UI)
Python API client (snap/2.9/CLI)
Python API client (snap/2.9/UI)
Python API client (deb/2.8/CLI)
Python API client (deb/2.8/UI)
Python API client (deb/2.9/UI)
The CLI cookbook (snap/2.7/CLI)
The CLI cookbook (snap/2.7/UI)
The CLI cookbook (snap/2.8/UI)
CLI resource pool management
The CLI cookbook (deb/2.7/UI)
The CLI cookbook (deb/2.8/UI)
The CLI cookbook (deb/2.9/CLI)
The CLI cookbook (snap/2.8/CLI)
The CLI cookbook (deb/2.8/CLI)
The CLI cookbook (snap/2.9/CLI)
The CLI cookbook (deb/2.7/CLI)
The CLI cookbook (deb/2.9/UI)
User accounts (snap/2.8/UI)
User accounts (snap/2.7/UI)
User accounts (snap/2.9/UI)
User accounts (deb/2.7/UI)
User accounts (deb/2.8/UI)
User accounts (deb/2.9/UI)
Power management (snap/2.7/CLI)
Power management (snap/2.8/CLI)
Power management (deb/2.8/CLI)
Power management (deb/2.9/CLI)
Power management (deb/2.7/CLI)
Power management (snap/2.9/CLI)
Custom machine setup (snap/2.7/CLI)
Custom machine setup (snap/2.8/CLI)
Custom machine setup (snap/2.9/CLI)
Custom machine setup (deb/2.8/CLI)
Custom machine setup (deb/2.9/CLI)
Custom machine setup (deb/2.7/CLI)
Disk erasure (snap/2.7/CLI)
Disk erasure (deb/2.7/CLI)
Disk erasure (deb/2.9/CLI)
Disk erasure (snap/2.8/CLI)
Disk erasure (deb/2.8/CLI)
Disk erasure (snap/2.9/CLI)
The CLI cookbook (snap/2.9/UI)
User accounts (CLI)
CLI kernel management
CLI tag management
User accounts

in that scripts of maas-login.sh

we seem like lost something,
“localhost” should probably write “localhost:5240”

1 Like