簡単なデバッグコマンド:
ansible -i inventory/hosts.yaml -m debug -a "var=hostvars[inventory_hostname]" all
出力:
"hostvars[inventory_hostname]": {
"ansible_check_mode": false,
"ansible_diff_mode": false,
"ansible_facts": {},
"ansible_forks": 5,
"ansible_host": "192.168.10.125",
"ansible_inventory_sources": [
"/root/workspace/ansible-minicros/inventory/hosts.yaml"
],
"ansible_playbook_python": "/usr/bin/python2",
"ansible_port": 65532,
"ansible_verbosity": 0,
"ansible_version": {
"full": "2.8.5",
"major": 2,
"minor": 8,
"revision": 5,
"string": "2.8.5"
},
ホストのIPアドレスを取得します。
ansible -i inventory/hosts.yaml -m debug -a "var=hostvars[inventory_hostname].ansible_host" all
zk01 | SUCCESS => {
"hostvars[inventory_hostname].ansible_host": "192.168.10.125"
}