【发布时间】:2020-02-19 05:18:36
【问题描述】:
我有一个可读取文件列表并为这些值设置寄存器的 ansible 剧本。然后我想将文件列表传递给include_role 任务。以下是我当前的代码。
- name: Get list of files
command: "sh -c 'find playbooks/vars/files/*.yml'"
register: find_files
- include_vars:
file: "{{ item }}"
loop: "{{ find_files.stdout_lines }}"
register: result
- name: call role
include_role:
name: myRole
loop: "{{ result.results }}"
当 playbook 运行时,它会在目录中找到两个文件; file1.yml 和 file2.yml。但是当它通过include_role 循环时,它会通过file1.yml 两次并且永远不会通过file2.yml。试图确定我如何确保file2.yml 也被传递给角色。
【问题讨论】:
-
我不相信循环遍历
include_role:(尤其是当name:是常量时)除了浪费CPU 之外不会做任何事情;您是否尝试将不同的 变量 传递给角色?另外,command: sh -c ""也称为shell:
标签: loops ansible include roles