Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.0k views
in Technique[技术] by (71.8m points)

ansible - How to use 'skip: true' with '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] ***************************************
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"}

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?

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.

Answering your question:

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...