我的劇本:沒有IP信息
- hosts: master
gather_facts: True
become: True
tasks:
- set_fact: headnode={{ ansible_all_ipv4_addresses[0] }}
- hosts: slave
become: True
tasks:
- debug: msg={{ hostvars.master }}
而且沒有事實headnode
那裏。我錯過了什麼嗎?另外,hostvars.master
不包含['ansible_eth0']
那麼所有的文檔都是錯誤的?
這不也是工作:hostvars['master ']['ansible_eth0']['ipv4']['address']
這:可以從清單文件
ok: [slave0] => {
"msg": {
"ansible_check_mode": false,
"ansible_ssh_host": "xxx.westeurope.cloudapp.azure.com",
"ansible_ssh_port": 22,
"ansible_ssh_private_key_file": "/root/.ssh/id_rsa",
"ansible_ssh_user": "vagrant",
"ansible_version": {
"full": "2.2.2.0",
"major": 2,
"minor": 2,
"revision": 2,
"string": "2.2.2.0"
},
"group_names": [
"master"
],
"groups": {
"all": [
"master",
"slave0"
],
"master": [
"master"
],
"slave": [
"slave0"
],
"ungrouped": []
},
"inventory_dir": "/xxx/.vagrant/provisioners/ansible/inventory",
"inventory_file": null,
"inventory_hostname": "master",
"inventory_hostname_short": "master",
"omit": "__omit_place_holder__fb9f90a73039d94f14c1a1f0af132f1c36b9fb4a",
"playbook_dir": "/xxx/ansible"
}
}
不收集事實(沒有一個事實,即不僅IP地址丟失,一切都丟失)。不要問我爲什麼。檢查你的日誌。 – techraf
你如何運行劇本?它由Vagrant執行嗎?你確定在兩臺機器都存在的情況下運行這本手冊嗎?並且,例如,執行不限於一次一臺機器? – techraf