当我尝试通过运行角色并将其委托给主机 2(下面的代码)来执行以下剧本时,include_role 和 delegate_to 是否可以在 Ansible 2.9 中协同工作?
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: …Run Code Online (Sandbox Code Playgroud) ansible ×1