如何使用 'skip: true' 和 'with_first_found'?
How to use 'skip: true' with 'with_first_found'?
我想在剧本中使用以下任务:
- include: "{{ prerequisites_file }}"
with_first_found:
- "prerequisites-{{ ansible_distribution }}.yml"
- "prerequisites-{{ ansible_os_family }}.yml"
loop_control:
loop_var: prerequisites_file
如果没有找到与体系结构匹配的文件,我希望它通过。
当运行原样时,在这种情况下,会产生错误:
TASK [ansible-playbook : include] ***************************************
fatal: [ansible-playbook]: FAILED! => {"failed": true, "msg": "No file was found when using with_first_found. Use the 'skip: true' option to allow this task to be skipped if no files are found"}
我知道我可以在最后添加一个虚拟文件,但如果我按照建议,我应该如何在此处添加 skip: true
选项?
这绝对不是 include
模块的参数,它应该以某种方式绑定到 with_first_found
子句...
with_first_found
有很多参数变化。
看看 first_found.py – 文件开头有一些示例。
回答您的问题:
- include: "{{ prerequisites_file }}"
with_first_found:
- files:
- "prerequisites-{{ ansible_distribution }}.yml"
- "prerequisites-{{ ansible_os_family }}.yml"
skip: true
loop_control:
loop_var: prerequisites_file
我想在剧本中使用以下任务:
- include: "{{ prerequisites_file }}"
with_first_found:
- "prerequisites-{{ ansible_distribution }}.yml"
- "prerequisites-{{ ansible_os_family }}.yml"
loop_control:
loop_var: prerequisites_file
如果没有找到与体系结构匹配的文件,我希望它通过。
当运行原样时,在这种情况下,会产生错误:
TASK [ansible-playbook : include] ***************************************
fatal: [ansible-playbook]: FAILED! => {"failed": true, "msg": "No file was found when using with_first_found. Use the 'skip: true' option to allow this task to be skipped if no files are found"}
我知道我可以在最后添加一个虚拟文件,但如果我按照建议,我应该如何在此处添加 skip: true
选项?
这绝对不是 include
模块的参数,它应该以某种方式绑定到 with_first_found
子句...
with_first_found
有很多参数变化。
看看 first_found.py – 文件开头有一些示例。
回答您的问题:
- include: "{{ prerequisites_file }}"
with_first_found:
- files:
- "prerequisites-{{ ansible_distribution }}.yml"
- "prerequisites-{{ ansible_os_family }}.yml"
skip: true
loop_control:
loop_var: prerequisites_file