Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/lig/pyventory
Ansible Inventory implementation that uses Python syntax
https://github.com/lig/pyventory
ansible inventory python python3 terraform
Last synced: 3 months ago
JSON representation
Ansible Inventory implementation that uses Python syntax
- Host: GitHub
- URL: https://github.com/lig/pyventory
- Owner: lig
- License: mit
- Created: 2016-11-25T14:14:16.000Z (about 8 years ago)
- Default Branch: main
- Last Pushed: 2022-12-09T08:33:07.000Z (about 2 years ago)
- Last Synced: 2024-09-27T15:04:34.474Z (3 months ago)
- Topics: ansible, inventory, python, python3, terraform
- Language: Python
- Homepage: https://pyventory.readthedocs.io
- Size: 132 KB
- Stars: 24
- Watchers: 5
- Forks: 3
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
[![CI Status](https://github.com/lig/pyventory/workflows/CI/badge.svg)](https://github.com/lig/pyventory/actions)
# Pyventory
Ansible Inventory implementation that uses Python syntax
## Install
```shell
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](https://docs.python.org/3/library/string.html#format-specification-mini-language).
* 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:
```python
#!/usr/bin/env python3
from pyventory import Asset, ansible_inventoryclass All(Asset):
run_tests = False
use_redis = False
redis_host = 'localhost'
minify = False
version = 'develop'class Staging(All):
run_tests = Truestaging = Staging()
ansible_inventory(locals())
```Consider a [more complex example](tests/example) which passes the following [json output](tests/example.json) to Ansible.
Run Ansible playbook with the `-i hosts.py` key:
```shell
ansible-playbook -i hosts.py site.yml
```Notice that you need to have your inventory package in `PYTHONPATH`.