Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use 'skip: true' with 'with_first_found'?

Tags:

ansible

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...

like image 978
techraf Avatar asked Dec 10 '22 14:12

techraf


1 Answers

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
like image 62
Konstantin Suvorov Avatar answered Jan 06 '23 22:01

Konstantin Suvorov