Coder Social home page Coder Social logo

ansible-maas-dynamic-inventory's Introduction

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.