Ansible:将剧本中的任务限制为本地主机
我想限制Ansible播放到特定的主持人 以下是我想要的精简版本:Ansible:将剧本中的任务限制为本地主机,ansible,ansible-2.x,Ansible,Ansible 2.x,我想限制Ansible播放到特定的主持人 以下是我想要的精简版本: - hosts some_host_group tasks: - name: Remove existing server files hosts: 127.0.0.1 file: dest: /tmp/test_file state: present - name: DO some other stuff file: ... 我想(作为早期任务)删除一个本地目录(我在示例中创
- hosts some_host_group
tasks:
- name: Remove existing server files
hosts: 127.0.0.1
file:
dest: /tmp/test_file
state: present
- name: DO some other stuff
file:
...
我想(作为早期任务)删除一个本地目录(我在示例中创建了一个文件,因为这是一个更容易观察的测试)。我的印象是,我可以将一个游戏限制为一组主机,并将“hosts”参数用于任务-
但我得到了这个错误:
ERROR! 'hosts' is not a valid attribute for a Task
$ansible --version
ansible 2.3.1.0
谢谢
PS我可以将ansible封装在一个shell片段中,但这太难看了。您的剧本中有语法错误,请查看,然后
您的剧本中有语法错误,请查看,然后 您应该使用并告诉Ansible to(否则它将尝试删除目录的次数与您游戏中的目标主机相同,尽管这不会是一个问题) 如前所述,如果要删除目录,还应使用
缺席
notpresent
您应该使用并告诉Ansible to(否则它将尝试删除目录的次数与您游戏中的目标主机相同,尽管这不会是一个问题)
如前所述,如果要删除目录,还应使用缺席
notpresent
我知道有个错误——我在问题中提到过。我喜欢您在多主机部分描述的方法,但这似乎不起作用。我知道有一个错误-我在问题中提到过。我喜欢您在多主机部分描述的方法,但这似乎不起作用。
- hosts: some_host_group
tasks:
- name: Remove existing server files
- hosts: localhost
tasks:
- file:
dest: /tmp/test_file
state: present
- name: DO some other stuff
file:
- name: Remove existing server files
delegate_to: 127.0.0.1
run_once: true
file:
dest: /tmp/test_file
state: absent