Package: ansible-dynamic-inventory
# ansible-dynamic-inventoryGenerate ansible dynamic inventory from static inventory.Optionally, Replace the host list of ansible static inventory with ServiceAddress registered in consul service.[![PyPI version](https://badge.fury.io/py/ansible-dynamic-inventory.svg)](https://badge.fury.io/py/ansible-dynamic-inventory)![Python Version](https://img.shields.io/badge/python-2.7-blue.svg)[![Build Status](https://travis-ci.org/Yoshiyuki-Nakahara/python-ansible-dynamic-inventory.svg?branch=master)](https://travis-ci.org/Yoshiyuki-Nakahara/python-ansible-dynamic-inventory)[![Code Health](https://landscape.io/github/Yoshiyuki-Nakahara/python-ansible-dynamic-inventory/master/landscape.svg?style=plastic)](https://landscape.io/github/Yoshiyuki-Nakahara/python-ansible-dynamic-inventory/master)[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)# Assumed Use Case- Dynamic inventory conversion from Static inventory- Merge Dynamic inventory into Static inventorycf. gce.py(dynamic inventory) + group_vars(static inventory)- In the service operated using [Consul](https://www.consul.io/), inventory is dynamically generated without rewriting static inventory when host information changes dynamically, such as automatic failover- Confirm the inventory structure with plantuml# References[Ansible inventory](http://docs.ansible.com/ansible/intro_inventory.html)[Ansible Dynamic Inventory](http://docs.ansible.com/ansible/intro_dynamic_inventory.html)[Consul Catalog Service](https://www.consul.io/docs/agent/http/catalog.html#catalog_service)# Installation$ yum install gcc python-devel openssl-devel python-pip$ pip install --upgrade pip setuptools (optional)$ pip install ansible-dynamic-inventory# Prerequisite of Replace with Consul ServiceIf the group name written in the ansible static inventory and the service name registered in the consul service are the same, the host name is replaced.# Usage# Stand alone execution$ ansible-dynamic-inventory --list# Stand alone execution and specified config file$ ansible-dynamic-inventory --list --config /path/to/config# or Specify config file with environment variable$ ANSIBLE_DYNAMIC_INVENTORY_CONFIG_PATH=/path/to/config ansible-dynamic-inventory --list# As Ansible Dynamic Inventory execution$ ansible-playbook --inventory ansible-dynamic-inventory /path/to/playbook.yml# outut in platuml formatansible-dynamic-inventory --plantuml# Configuration# vi ansible_dynamic_inventory.ini[ansible]# If both static_inventory_path and dynamic_inventory_path are specified,# merge dynamic_inventory into static_inventory# Either static_inventory_path or dynamic_inventory_path must not be empty# path to static inventory file or directorystatic_inventory_path = /path/to/ansible_inventory# path to dynamic inventory file#dynamic_inventory_path = ./gce.pydynamic_inventory_path =[consul]#url = http://localhost:8500/v1url =# Stand alone execution exampleex. ansible:static_inventory_path = ${this repository}/sample_inventory$ ansible-dynamic-inventory --list{"all": {"hosts": ["10.10.10.12","10.10.10.13","10.10.10.14","10.10.10.15","10.10.10.11"],"children": ["ungrouped","_mysql_replication_config","mysql_backup_storage"],"vars": {"datacenter": "vagrant","net_cidr": "10.10.10.0/24"}},"_mysql_replication_config": {"hosts": ["10.10.10.12","10.10.10.13","10.10.10.14","10.10.10.15","10.10.10.11"],"children": ["mysql_replication_master","mysql_replication_slave","mysql_replication_backup","mysql_failover"],"vars": {"mysql_replication_user": "root","mysql_master_host": "{{groups.mysql_replication_master[0]}}","mysql_master_group_name": "mysql_replication_master","mysql_version": "5.6.34","mysql_replication_group_name": "single","mysql_slave_group_name": "mysql_replication_slave"}},"_meta": {"hostvars": {"10.10.10.15": {},"10.10.10.14": {},"10.10.10.11": {},"10.10.10.13": {},"10.10.10.12": {"hostvar": "dummy"}}},"mysql_backup_storage": {"hosts": ["10.10.10.15"],"vars": {"mysql_backup_target_host": "{{groups.mysql_replication_backup[0]}}","mysql_backup_storage_cron_file": "../../../../varfiles/vagrant/mysql/backup_storage/mysql_backup"}},"mysql_replication_slave": {"hosts": ["10.10.10.13","10.10.10.14"]},"mysql_replication_backup": {"hosts": ["10.10.10.15"]},"ungrouped": {},"mysql_failover": {"hosts": ["10.10.10.11"],"vars": {"mysql_failover_config_file": "../../../../varfiles/vagrant/mysql/failover/config.yml"}},"mysql_replication_master": {"hosts": ["10.10.10.12"]}}# output in platuml format exampleex. ansible:static_inventory_path = ${this repository}/sample_inventory- Ansible host information is converted in plantuml "object"- Ansible group information is converted in plantuml "package"- Ansible group variable information is converted in plantuml "class"$ /usr/bin/ansible-dynamic-inventory --plantuml@startumlobject 10.10.10.15object 10.10.10.14object 10.10.10.11object 10.10.10.13object 10.10.10.12 {"hostvar": "dummy"}package all {all_hosts - 10.10.10.12all_hosts - 10.10.10.13all_hosts - 10.10.10.14all_hosts - 10.10.10.15all_hosts - 10.10.10.11class all_varsall_children - ungroupedall_children - _mysql_replication_configall_children - mysql_backup_storage}class all_vars {"datacenter": "vagrant""net_cidr": "10.10.10.0/24"}package _mysql_replication_config {_mysql_replication_config_hosts - 10.10.10.12_mysql_replication_config_hosts - 10.10.10.13_mysql_replication_config_hosts - 10.10.10.14_mysql_replication_config_hosts - 10.10.10.15_mysql_replication_config_hosts - 10.10.10.11class _mysql_replication_config_vars_mysql_replication_config_children - mysql_replication_master_mysql_replication_config_children - mysql_replication_slave_mysql_replication_config_children - mysql_replication_backup_mysql_replication_config_children - mysql_failover}class _mysql_replication_config_vars {"mysql_replication_user": "root""mysql_master_host": "{{groups.mysql_replication_master[0]}}""mysql_master_group_name": "mysql_replication_master""mysql_version": "5.6.34""mysql_replication_group_name": "single""mysql_slave_group_name": "mysql_replication_slave"}package mysql_backup_storage {mysql_backup_storage_hosts - 10.10.10.15class mysql_backup_storage_vars}class mysql_backup_storage_vars {"mysql_backup_target_host": "{{groups.mysql_replication_backup[0]}}""mysql_backup_storage_cron_file": "../../../../varfiles/vagrant/mysql/backup_storage/mysql_backup"}package mysql_replication_slave {mysql_replication_slave_hosts - 10.10.10.13mysql_replication_slave_hosts - 10.10.10.14}package mysql_replication_backup {mysql_replication_backup_hosts - 10.10.10.15}package ungrouped {}package mysql_failover {mysql_failover_hosts - 10.10.10.11class mysql_failover_vars}class mysql_failover_vars {"mysql_failover_config_file": "../../../../varfiles/vagrant/mysql/failover/config.yml"}package mysql_replication_master {mysql_replication_master_hosts - 10.10.10.12}@enduml# LicenseMIT License