【发布时间】:2020-07-23 10:28:49
【问题描述】:
include_role 和 delegate_to 在 Ansible 2.9 中是否一起工作,因为我试图通过运行一个角色并将其委派给主机 2(下面的代码)来执行以下剧本?
Ansible 剧本
- name: top level playbook
hosts: ["host1", "host2"]
connection: local
gather_facts: true
ignore_errors: no
tasks:
- set_fact:
playbook_dir: /Users/OneDrive
validation_overall: 'pass'
result: {}
all_hosts: "{{ ansible_play_hosts }}"
- name: import hostvars
include_vars:
dir: '{{ playbook_dir }}/test_env_vars/hostvars'
files_matching: '{{ inventory_hostname }}.*'
- name: initialise required input variables
set_fact:
input_interfaces: "{{ e_input_interfaces }}"
# delegate role to host2
- name: "call validate_rtr_state role with host '{{ansible_hostname}}' for hosts in '{{ansible_play_hosts}}'"
include_role:
name: validate_rtr_state
tasks_from: cisco-ios-xr_ping.yml
apply:
delegate_to: "{{all_hosts[1]}}"
loop: "{{ansible_play_hosts}}"
loop_control:
loop_var: all_hosts[1]
我收到的错误信息如下:
ERROR! conflicting action statements: apply, include_role
The error appears to be in '/home/bbann/Ansible-Networking/ha_failover_top_level_reload.yml': line 46, column 7, but may
be elsewhere in the file depending on the exact syntax problem.
The offending line appears to be:
# delegate role to tusredrweca908
- name: "call validate_rtr_state role with host '{{ansible_hostname}}' for hosts in '{{ansible_play_hosts}}'"
^ here
我们可能错了,但这个看起来可能是一个问题 缺少引号。总是引用模板表达式括号 开始一个值。例如:
with_items:
- {{ foo }}
应该写成:
with_items:
- "{{ foo }}"
任何想法为什么会失败?
【问题讨论】:
标签: ansible