Ansible 在一台主机上执行命令,所有清单主机都在参数中
是否可以在参数中包含所有库存主机的主机上执行命令 例如: 库存文件:Ansible 在一台主机上执行命令,所有清单主机都在参数中,ansible,Ansible,是否可以在参数中包含所有库存主机的主机上执行命令 例如: 库存文件: host1 host2 host3 我只想从主机1执行此命令: ssh toto@host1:"touch /tmp/test" ssh toto@host2:"touch /tmp/test" ssh toto@host3:"touch /tmp/test" 为此,我使用此代码,但它不起作用。该代码仅在一台主机上执行 name: Execute test command: ssh toto@{{ inventory_
host1
host2
host3
我只想从主机1执行此命令:
ssh toto@host1:"touch /tmp/test"
ssh toto@host2:"touch /tmp/test"
ssh toto@host3:"touch /tmp/test"
为此,我使用此代码,但它不起作用。该代码仅在一台主机上执行
name: Execute test
command: ssh toto@{{ inventory_hostname }}:"touch /tmp/test"
delegate_to: host1
那么:
- hosts: host1
tasks:
- name: execute test
command: ssh toto@{item} touch /tmp/test
loop: "{{ groups.all }}"
这将迭代组.all
,其中包含库存中每个主机的名称