我有一個劇本,它有多個角色和串行設置,以便它在一臺機器上運行,然後在其他機器上運行。在其中一個角色,我有以下任務:Ansible循環相關問題
- name: getting dbnodes IP addresses
local_action: shell echo "{% for host in groups['dbnodes'] %}{{ hostvars[host]['ansible_eth0']['ipv4']['address'] }},{% endfor %}"
run_once: true
register: IPS
基本上就是我想要做的就是收集所有主機的IP地址,並與IPS註冊它以便今後使用。但是由於串行(我認爲),下面的錯誤導致任務失敗。
TASK [dbcluster : getting dbnodes IP addresses] ******************************** fatal: [162.220.52.190]: FAILED! => {"failed": true, "msg": "the field 'action' has an invalid value, which appears to include a variable that is undefined. The error was: 'dict object' has no attribute 'ansible_eth0'\n\nThe error appears to have been in '/root/tenon-delivery/ansible/roles/dbcluster/tasks/main.yml': line 52, column 3, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n\n- name: getting dbnodes IP addresses\n^here\n"}
在運行ansible dbnode -s setup
我可以看到ansible_eth0有一個適當的值。我不明白爲什麼它說這是未定義的。
任何想法如何在同一時間收集所有機器上的事實,同時仍然可以選擇幾個任務/處理程序仍在串行化。
更新的問題,因爲我得到了更多的信息 – zozo6015
您對串行運行的話什麼都不用改。做一個單獨的遊戲收集所有的事實,然後做其他事情。 –
實際上它確實會改變原因,如果我禁用串行然後事實收集工作。這種情況下的問題是如何在一個劇本中使用變量集到另一個劇本中。 – zozo6015