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