Git Product home page Git Product logo

ansible-git-inventory's Introduction

Description

This is a dynamic inventory script for Ansible and the Ansible Tower. It reads hosts and groups from a git repositories' YAML file and "magically" transforms them into a dynamic inventory source for Ansible or the Ansible Tower API.

It has a few advantages over the static definition of hosts / groups in the Tower:

  • hosts and groups can be maintained directly in git next to the Ansible plays/roles/variables
  • host/group changes will be tagged together with the rest in the git repo
  • management of complex host/group structures get simplified
  • better overview thanks to the YAML instead of the WebUI

The provided YAML has a predefined layout, which is required for the scripts "magic" host group algorithm. Here's an example of a YAML file called prod.yml:

---
web:
    site1:
        - web1
        - web2
    site2:
        - web3
        - web4
db:
    site1:
        - db1
        - db2
    site2:
        - db3
        - db4

When the YAML file is parsed by the script, you'll have access to several host groups:

  • tier groups like web, db:
  • location groups like site1, site2:
  • tier-location groups like web-site1, web-site2, db-site1, db-site2

Because the file name is based on the environment, for example prod.yml, you also have access to environment based host groups:

  • env groups like prod
  • env-tier groups like prod-web, prod-db
  • env-location groups like prod-site1, prod-site2
  • env-tier-location groups like prod-web-site1, prod-web-site2, prod-db-site1, prod-db-site2

Installation

Ansible stand-alone script

  • Download a relase from this repository.
  • Install the requirements by executing
pip install -r requirements.txt

Ansible Tower (one-time)

  • Browse to the Ansible Tower WebUI
  • Login as an user with administration privileges
  • Click on the Administration icon on the upper right corner
  • Click on the Inventory Scripts link
  • Create a new Inventory Script by clicking on the + icon
  • Drag n' drop or copy-paste this script into the text field
  • Fill out the rest of the form and click Save

Configuration

Configure Tower Inventory

  • Open an existing inventory in the Ansible Tower WebUI
  • Create a new group by clicking the plus icon
  • Enter a name for the new (parent) group (e.g. dynamic)
  • Click on the Source tab
  • Select the custom script you've created in the last step

Please note you can / must set the following environment variables:

  • URL: URL of the git repository, mandatory
  • INVENTORY: Path of the inventory file, mandatory
  • SSHKEY: Path to an alternate SSH key, optional
  • COMMIT: Commit to checkout (i.e. branch or tag), optional

ansible-git-inventory's People

Contributors

domibarton avatar

Watchers

 avatar  avatar

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.