Generate a dynamic Ansible inventory of Saltstack minions using the Python salt client API
-
Run from the salt master server.
-
Requires access to the salt Python module.
-
If your Ansible is housed in a virtualenv source the venv and install salt. Otherwise the venv ansible will call the python script and not be able to find Python salt modules.
source ../venv/bin/activate pip install salt
-
-
Check the list of minions the script provides
./saltstack_inventory.py --list -
Check an individual host (only returns ipv4)
./saltstack_inventory.py --list store-0
-
Download the
saltstack_inventory.pyscript -
Execute
ansibleoransible-playbookusing--inventory <path>/saltstack_inventory.py# ansible --inventory ./saltstack_inventory.py -m ping stor\* store-0 | SUCCESS => { "changed": false, "ping": "pong" } store-5 | SUCCESS => { "changed": false, "ping": "pong" } store-4 | SUCCESS => { "changed": false, "ping": "pong" } store-2 | SUCCESS => { "changed": false, "ping": "pong" } store-1 | SUCCESS => { "changed": false, "ping": "pong" } store-3 | SUCCESS => { "changed": false, "ping": "pong" }