MAAS tags (snap/2.9/CLI)

2.7 2.8 2.9 3.0
Snap CLI ~ UI CLI ~ UI CLI ~ UI CLI ~ UI
Packages CLI ~ UI CLI ~ UI CLI ~ UI CLI ~ UI

Tags are a convenient way to assign descriptive words to machines, interfaces, and storage devices. Using MAAS tags, you can easily select machines that meet certain criteria, helping you to remember that you’ve defined or reserved certain machines for certain functions.

Tag names can include any combination of letters, numbers, dashes (-) and underscores (_), and be a maximum of 256 characters in length.

Tags are added to machines in one of three ways:

  • A user manually applies the tag to a machine.
  • The tag has been defined and it is applied after the machine is commissioned.
  • The tag has been defined and the user runs the CLI command maas $PROFILE tag rebuild $TAG, which automatically applies the tag to all machines regardless of state.

Ten questions you may have:

  1. How can I set kernel boot options for a specific machine?
  2. How do I create tags?
  3. How do I do tag creation and auto-assignment?
  4. How do I delete a tag?
  5. How do I list all tags?
  6. How do I list nodes/machines labelled with a tag?
  7. How can I update a tag without recommissioning my machines?
  8. How do I handle Juju integration?
  9. How do I effect manual tag assignment?
  10. How do I effect hybrid tag assignment?

Tag creation

maas $PROFILE tags create name=$TAG_NAME

Tag creation and auto-assignment

When you supply a definition during a tag’s creation, MAAS automatically applies the tag to all the nodes that satisfy the definition:

maas $PROFILE tags create name=$TAG_NAME \
    comment='$TAG_COMMENT' definition='$TAG_DEFINITION'

For example,

maas $PROFILE tags create name='gpu' \
    comment='GPU with clock speed >1GHz for running CUDA type operations.' \
    definition='//node[@id="display"]/'clock units="Hz"' > 1000000000'

We recommend that each tag have a short name and a comment that adequately describes it. You should make sure to create both of these because they will help you identify and use the tag later.

Tags for network interfaces

It’s also possible to assign tags to specific network interfaces. You can use these tags when searching for machines within the web UI and when allocating machines from the API.

Network interface tags can only be assigned when a machine is in either a ‘Ready’ or a ‘Broken’ state.

To add a tag to a network interface, use the following command:

maas $PROFILE interface add-tag $SYSTEM_ID $INTERFACE_ID tag=$TAG_STRING

To delete a tag from a network interface:

maas $PROFILE interface remove-tag $SYSTEM_ID $INTERFACE_ID tag=$TAG_STRING

Tags for network interfaces

It’s also possible to assign tags to specific network interfaces. You can use these tags when searching for machines within the web UI and when allocating machines from the API.

Network interface tags can only be assigned when a machine is in either a ‘Ready’ or a ‘Broken’ state.

To add a tag to a network interface, use the following command:

maas $PROFILE interface add-tag $SYSTEM_ID $INTERFACE_ID tag=$TAG_STRING

To delete a tag from a network interface:

maas $PROFILE interface remove-tag $SYSTEM_ID $INTERFACE_ID tag=$TAG_STRING

Delete a tag

maas $PROFILE tag delete $TAG_NAME

List all tags

To list all tags present on the region controller:

maas $PROFILE tags read

List nodes/machines labelled with a tag

To list what nodes (or machines) a tag applies to:

maas $PROFILE tag nodes $TAG_NAME
maas $PROFILE tag machines $TAG_NAME

Juju integration

Although you can use a tag in the web UI (as a node search filter), you realise most of the benefit when you’re deploying applications with Juju.

For example, to use the ‘gpu’ tag to deploy a (hypothetical) service called ‘cuda’:

juju deploy --constraints tags=gpu cuda

You can also use multiple tags in addition to the normal Juju constraints:

juju deploy --constraints "mem=1024 tags=gpu,intel" cuda

Manual tag assignment

It is possible to assign tags to nodes manually by simply omitting the definition and applying the tag to a node by referencing its system id:

maas $PROFILE tags create name=$TAG_NAME comment='$TAG_COMMENT'
maas $PROFILE tag update-nodes $TAG_NAME add=$SYSTEM_ID

To remove a tag:

maas $PROFILE tag update-nodes $TAG_NAME remove=$SYSTEM_ID

In the same operation, a tag can be added to some nodes and removed from others:

maas $PROFILE tag update-nodes $TAG_NAME \
    add=$SYSTEM_ID_1 add=$SYSTEM_ID_2 remove=$SYSTEM_ID_3

Hybrid tag assignment

You can also create a tag with a definition (thereby map to certain nodes), remove the definition (but retain the mapping), and then add the tag manually to specific nodes. This action is useful for hardware which is conceptually similar but does not all satisfy a single tag definition. Here are the commands you would use to do this:

maas $PROFILE tags create name=$TAG_NAME \
    comment='$TAG_COMMENT' definition='$TAG_DEFINITION'
maas $PROFILE tag update $TAG_NAME definition=''
maas $PROFILE tag update-nodes $TAG_NAME add=$SYSTEM_ID

Per-machine kernel boot options

Per-machine kernel boot options are set using the CLI.

Per-machine boot options take precedence to global ones. Please also note that, even though a deployed machine has a kernel_opt tag applied, MAAS won’t apply the kernel_opt associated with that tag until the next deployment. This means that a machine that has been deployed for a long time can (possibly) inherit kernel options that were applied in the distant past.

To specify kernel boot options for an individual machine, first create a tag:

maas $PROFILE tags create name='$TAG_NAME' \
    comment='$COMMENT' kernel_opts='$KERNEL_OPTIONS'

For example:

maas $PROFILE tags create name='nomodeset' \
    comment='nomodeset kernel option' kernel_opts='nomodeset vga'

Next, assign the tag to the machine in question:

maas $PROFILE tag update-nodes $TAG_NAME add=$SYSTEM_ID

If multiple tags attached to a machine have the kernel_opts defined, MAAS uses the first one found, in alphabetical order.

Updating tags without commissioning

If you need to update tags for all machines – without having to recommission them – you can accomplish this with the rebuild command:

maas $PROFILE tag rebuild $TAG

This command automatically applies the tag to all machines regardless of state, even machines that are actively deployed.

Hi, the CLI tag management link on the bottom of https://maas.io/docs/snap/2.9/cli/maas-tags is broken and links to https://maas.io/t/cli-tag-management/801 which is a 404.

1 Like

thank, @szeestraten, that’s basically a typo. nice catch! i’ll fix it here shortly.