12345678910111213141516171819202122232425262728293031 |
- #compdef ossh oscp
- _ossh_known_hosts(){
- if python -c 'import openshift_ansible' &>/dev/null; then
- print $(/usr/bin/python -c 'from openshift_ansible import multi_inventory; m=multi_inventory.MultiInventory(); m.run(); z=m.result; print "\n".join([name for name in z["_meta"]["hostvars"].keys()])')
- elif [[ -f /dev/shm/.ansible/tmp/multi_inventory.cache ]]; then
- print $(/usr/bin/python -c 'import json; loc="/dev/shm/.ansible/tmp/multi_inventory.cache"; z=json.loads(open(loc).read()); print "\n".join([name for name in z["_meta"]["hostvars"].keys() ])')
- elif [[ -f ~/.ansible/tmp/multi_inventory.cache ]]; then
- print $(/usr/bin/python -c 'import json,os; loc="%s" % os.path.expanduser("~/.ansible/tmp/multi_inventory.cache"); z=json.loads(open(loc).read()); print "\n".join([name for name in z["_meta"]["hostvars"].keys() ])')
- fi
- }
- _ossh(){
- local curcontext="$curcontext" state line
- typeset -A opt_args
- #_arguments "*:Hosts:_ossh_known_hosts"
- _arguments -s : \
- "*:hosts:->hosts"
- case "$state" in
- hosts)
- _values 'hosts' $(_ossh_known_hosts)
- ;;
- esac
- }
- _ossh "$@"
|