Dynamic inventory for MAAS
Find a file
Repository files (latest commit first)
Filename Latest commit message Latest commit date
renovate-bot 3f9a1a8198
All checks were successful
CI / lint (push) Successful in 51s
chore(deps): update dependency flake8 to v7.5.0 (#40)
2026-11-02 07:27:57 +00:00
.forgejo/workflows ci: add lint workflow (#33) 2026-09-28 07:41:00 +00:00
.gitignore Fix fixtures methods naming 2018-09-18 09:31:35 +01:00
.travis.yml Add travis 2018-09-12 01:15:00 +02:00
maas.ini Refactor code related to loading the configurations and its usage. 2018-09-24 19:06:22 +01:00
maas.py Fix to python3 2023-03-20 16:41:23 +01:00
README.md Update README.md to support single entry script 2018-09-20 14:34:27 +01:00
renovate.json chore: use the shared Renovate preset (#35) 2026-09-28 08:55:21 +00:00
requirements.txt chore(deps): update dependency flake8 to v7.5.0 (#40) 2026-11-02 07:27:57 +00:00
test_fixtures.py Update Test to support single entry script 2018-09-20 14:19:18 +01:00
test_inventories.py Fix test in order to use new cache settings structure. 2018-09-24 19:15:04 +01:00

Build Status License

ansible-maas-inventory

A inventory generator script to work with Ubuntu MAAS. It will generate your groups by looking at either the tags or hostname prefix you have in your MAAS nodes.

Requirements

  • Python3

Example

By looking at the tests it's quite easy to understand how it works. Just look at the fixtures file test_fixtures.py.

Set environment variables for MAAS_API_URL and MAAS_API_KEY. After that you can run

   $ python maas.py --list

and with ansible

    $ ansible -i maas.py some-playbook.yml

Output

{
    '_meta': {
        'hostvars': {
            'web-node1.dev': {
                'ansible_ssh_host': '127.0.0.1',
                'ansible_ssh_host_private': '127.0.0.1',
            },
            'web-node2.dev': {
                'ansible_ssh_host': '127.0.0.20',
                'ansible_ssh_host_private': '127.0.0.20',
            },
            'database1.dev': {
                'ansible_ssh_host': '192.168.0.1',
                'ansible_ssh_host_private': '192.168.0.1',
            },
            'database2.dev': {
                'ansible_ssh_host': '192.168.0.2',
                'ansible_ssh_host_private': '192.168.0.2',
            },
            'database3.dev': {
                'ansible_ssh_host': '192.168.0.4',
                'ansible_ssh_host_private': '192.168.0.4',
            },
        },
    },
    'web': {
        'hosts': [
            'web-node1.dev',
            'web-node2.dev',
        ],
        'vars': {},
    },
    'db': {
        'hosts': [
            'database1.dev',
            'database2.dev',
            'database3.dev',
        ],
        'vars': {},
    },
    'unnused_tag': {
        'hosts': [],
        'vars': {},
    },
}

Configuration

Configuration can be done by editing the maas.ini file or defining a new environment variable MAAS_INI_PATH indicating a new configuration file.

Available configuration:

[maas]
group_machines_by = tags | hostnames

[auth]
maas_api_key = XXXX:XXXX:XXXX
maas_api_url = https://docs.maas.io/MAAS/api/2.0/

[cache]
cache_path = ~/.ansible/tmp
cache_max_age = 300