Kidong Lee
1 min readMay 14, 2020

--

I have not tried writing a dynamic inventory script for my case, but you can try to write a custom dynamic inventory script which has to handle target_hosts of extra-vars variable using PPID and produces just the target hosts group json. This idea comes from someone who tried writing such script using PPID like this:

ansible-playbook -i inventory.sh deploy.yml -e cluster=cl_01> cat inventory.sh
#!/bin/bash
if [[ $1 != "--list" ]]; then exit 1; fi
cluster_extra_var=`ps -f --pid $PPID | grep ansible-playbook | grep -oh "cluster=\w*" | tail -1 | cut -f2 -d=`
./inventory.py --cluster $cluster_extra_var

See here: https://stackoverflow.com/questions/33920530/pass-a-parameter-to-ansibles-dynamic-inventory/39420844#39420844

--

--

Kidong Lee
Kidong Lee

Written by Kidong Lee

Founder of Cloud Chef Labs | Chango | Unified Data Lakehouse Platform | Iceberg centric Data Lakehouses https://www.cloudchef-labs.com/

No responses yet