我有一个剧本,其中有多个角色和串行设置,因此它首先在一台机器上运行,然后在其余机器上运行。在其中一个角色中,我有以下任务:
- 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 有一个正确的值。我不明白为什么它说它是未定义的。
知道如何同时收集所有机器上的事实,同时仍然可以选择仍在序列化多个任务/处理程序。
ansible_eth0
任务运行时事实可能是未知的。
您可能想要添加事实收集在你的剧本的最顶部播放:
- hosts: dbnodes
gather_facts: yes
tasks:
- debug: msg="facts gathering"
- hosts: othernodes
tasks:
- name: getting dbnodes IP addresses
...
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)