Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
289 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
# Pyventory | ||
Ansible Inventory implementation that uses Python syntax | ||
|
||
## Install | ||
|
||
```shell | ||
pip install pyventory | ||
``` | ||
|
||
## Featur e | ||
|
||
* Modular inventor y. | ||
* Assests inheritance using Python classe s. | ||
* 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 support | ||
* Python 2 (2.7) support | ||
|
||
|
||
## Usage | ||
|
||
Create `hosts.py` and make it executable. | ||
|
||
A short example of the `hosts.py` contents: | ||
|
||
```python | ||
#!/usr/bin/env python | ||
from pyventory import export_inventory | ||
|
||
class All(Asset): | ||
run_tests = False | ||
use_redis = False | ||
redis_host = 'localhost' | ||
minify = False | ||
version = 'develop' | ||
|
||
class Staging(All): | ||
run_tests = True | ||
|
||
staging = Staging() | ||
|
||
export_inventory(locals()) | ||
``` | ||
|
||
Consider a [more complex example](tests/e2e/example) which passes the following [json output](tests/e2e/example.json) to Ansible. | ||
|
||
Run Ansible playbook with the `-i hosts.py` key: | ||
|
||
```shell | ||
ansible-playbook -i hosts.py site.yml | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,19 @@ | ||
#!/usr/bin/env python3 | ||
#!/usr/bin/env python | ||
from pyventory import export_inventory | ||
|
||
from pyvars import * | ||
|
||
|
||
develop = DevelopHost() | ||
# develop_sidebranch = DevelopHost( | ||
# ansible_host='sidebranch_hostname', | ||
# version='sidebranch_name') | ||
# | ||
# staging = StagingHost() | ||
# | ||
# prod_backend1 = ProdBackEnd(num=1) | ||
# prod_backend2 = ProdBackEnd(num=2) | ||
# prod_frontend1 = ProdFrontEnd(num=1) | ||
# prod_frontend2 = ProdFrontEnd(num=2) | ||
develop_sidebranch = DevelopHost( | ||
ansible_host='sidebranch_hostname', | ||
version='sidebranch_name') | ||
|
||
staging = StagingHost() | ||
|
||
prod_backend1 = ProdBackEnd(num=1) | ||
prod_backend2 = ProdBackEnd(num=2) | ||
prod_frontend1 = ProdFrontEnd(num=1) | ||
prod_frontend2 = ProdFrontEnd(num=2) | ||
|
||
export_inventory(locals(), indent=4) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.