Script for generating infrastructure diagrams from Ansible inventory files
- Python 3.10, see #1 for Python 3.9 support;
- Before using this script you must install the Graphviz library on your system.
To prepare the JSON necessary to feed the script you must first prepare it using ansible-inventory
the following way (YAML, INI, and JSON formats can be used):
ansible-inventory -i inventory/example.yml --list > inventory/example.json
Note: The script currently is not able to parse inventories tha have many redefinitions of groups. To do so, a more intricate algorithm is necessary. Currently, a very naive one is implemented. To see what kind of inventory structure works well, see inventory/example.yml
.
Once you have an outputted JSON inventory file you can run the script:
python3 diagram/main.py -i inventory/example.json
For instructions run
python3 diagram/main.py -h
You will see the following
usage: ansible-inventory-diagram [-h] [-i INVENTORY]
[-o {png,jpg,svg,pdf,dot}] [-n NAME]
[-f FILENAME] [-s]
Script for generating infrastructure diagrams from Ansible inventory files
options:
-h, --help show this help message and exit
-i INVENTORY, --inventory INVENTORY
Path to Ansible JSON inventory file
-o {png,jpg,svg,pdf,dot}, --outformat {png,jpg,svg,pdf,dot}
Format of the output format
-n NAME, --name NAME Name of the diagram
-f FILENAME, --filename FILENAME
Name of file to output
-s, --show Show file after generation using the default program
2023 - mbrav https://github.com/mbrav/ansible-inventory-diagram
Clone repo
git clone https://github.com/mbrav/ansible-inventory-diagram.git
cd ansible-inventory-diagram
Install Python libraries
pip3 install -r requirements.txt
Run script
python3 diagram/main.py