如何将“skip: true"与“with_first_found"一起使用? [英] How to use 'skip: true' with 'with_first_found'?

查看:34
本文介绍了如何将“skip: true"与“with_first_found"一起使用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在剧本中使用以下任务:

I would like to use the following task in a playbook:

- include: "{{ prerequisites_file }}"
  with_first_found:
    - "prerequisites-{{ ansible_distribution }}.yml"
    - "prerequisites-{{ ansible_os_family }}.yml"
  loop_control:
    loop_var: prerequisites_file

如果没有找到与架构匹配的文件,我希望它通过.

I would like it to just pass if no files matching the architecture were found.

按原样运行时,在这种情况下会产生错误:

When run as is, in such a case, it produces an error:

TASK [ansible-playbook : include] *******************************************
致命的:[ansible-playbook]:失败!=> {"failed": true, "msg": "当使用 with_first_found 时没有找到文件.如果没有找到文件,请使用 'skip: true' 选项允许跳过此任务"}

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 选项?

I know I can add a dummy file at the end, but if I were to follow the advice, how am I supposed to add the skip: true option here?

这绝对不是 include 模块的参数,它应该以某种方式绑定到 with_first_found 子句...

It's definitely not an argument of the include module, it should be somehow bound to with_first_found clause...

推荐答案

with_first_found 有很多参数变化.
看看 first_found.py– 文件开头有一些示例.

with_first_found has a lot of parameters variations.
Take a look at first_found.py – there are some examples in the beginning of the file.

回答您的问题:

- include: "{{ prerequisites_file }}"
  with_first_found:
    - files:
        - "prerequisites-{{ ansible_distribution }}.yml"
        - "prerequisites-{{ ansible_os_family }}.yml"
      skip: true
  loop_control:
    loop_var: prerequisites_file

这篇关于如何将“skip: true"与“with_first_found"一起使用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆