我正在尝试使用以下任务创建主机文件。我在完全不属于组['hadoop']的机器上运行此任务。在这里,我想为来自组 ['hadoop'] 的节点创建主机文件,而不是在组 ['hadoop'] 上运行我的这个游戏
- name: Update /etc/hosts
lineinfile: dest=/etc/hosts
regexp='.*{{ item }}$'
line="{{ hostvars[item].ansible_default_ipv4.address }} {{item}}"
state=present
when: hostvars[item].ansible_default_ipv4.address is defined
with_items: groups['hadoop']
tags:
- etc-hosts
我试过了,但没有用,只有当我的游戏主机中有组['hadoop']时它才有效。
有人知道我在这里做错了什么吗?