项目作者: lig

项目描述 :
Ansible Inventory implementation that uses Python syntax
高级语言: Python
项目地址: git://github.com/lig/pyventory.git
创建时间: 2016-11-25T14:14:16Z
项目社区:https://github.com/lig/pyventory

开源协议:MIT License

下载


CI Status

Pyventory

Ansible Inventory implementation that uses Python syntax

Install

  1. pip3 install pyventory

Features

  • Modular inventory.
  • Assests inheritance using Python classes.
  • Support for multiple inheritance.
  • Support for mixins.
  • Support for vars templating using Python string formatting.
  • Python 3 (>=3.6) support.
  • Python 2 is not supported.

Usage

Create hosts.py and make it executable.

A short example of the hosts.py contents:

  1. #!/usr/bin/env python3
  2. from pyventory import Asset, ansible_inventory
  3. class All(Asset):
  4. run_tests = False
  5. use_redis = False
  6. redis_host = 'localhost'
  7. minify = False
  8. version = 'develop'
  9. class Staging(All):
  10. run_tests = True
  11. staging = Staging()
  12. ansible_inventory(locals())

Consider a more complex example which passes the following json output to Ansible.

Run Ansible playbook with the -i hosts.py key:

  1. ansible-playbook -i hosts.py site.yml

Notice that you need to have your inventory package in PYTHONPATH.