# How to stop fileglob lookup warning for not existing paths

**URL:** <https://forum.ansible.com/t/how-to-stop-fileglob-lookup-warning-for-not-existing-paths/36410>\
**Category:** Ansible Project\
**Created:** [March 8, 2022, 12:50pm UTC](https://forum.ansible.com/t/how-to-stop-fileglob-lookup-warning-for-not-existing-paths/36410 "2022-03-08T12:50:59Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![cloos](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/cloos/32/7297_2.png) [@cloos](https://forum.ansible.com/u/cloos)\
**Post date:** [March 8, 2022, 12:50pm UTC](https://forum.ansible.com/t/how-to-stop-fileglob-lookup-warning-for-not-existing-paths/36410/1 "2022-03-08T12:50:59Z")

</div>

Hi, I have the following task:

- ansible.builtin.copy:  
src: “{{ item }}”  
dest: /tmp/  
with\_fileglob: “files/tmp/{{ inventory\_hostname }}/\*.yaml”

Directory files/tmp/bar/ contains yaml files for host **bar**.  
Directory files/tmp/foo/ doesn’t exist because host **foo** should not receive any files with this task.

If I run this task on hosts **bar** and **foo** , I always get a warning:

[WARNING]: Unable to find ‘files/tmp/foo’ in expected paths (use -vvvvv to see paths)

I added a condition:  
when: inventory\_hostname == “bar”

and even wrapped the above task in a **block** with the above mentioned when condition,  
but I always get the warning.

Any idea how to stop the warning?

---

<div class="post-metadata">

**Author:** ![vbotka](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/vbotka/32/359_2.png) [@vbotka](https://forum.ansible.com/u/vbotka)\
**Post date:** [March 8, 2022, 2:00pm UTC](https://forum.ansible.com/t/how-to-stop-fileglob-lookup-warning-for-not-existing-paths/36410/2 "2022-03-08T14:00:16Z")

</div>

The simplest solution is to create empty directories if missing

&nbsp;&nbsp;&nbsp;&nbsp;- ansible.builtin.file:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;state: directory  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;path: "files/tmp/{{ inventory\_hostname }}"  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;delegate\_to: localhost

&nbsp;&nbsp;&nbsp;&nbsp;- ansible.builtin.copy:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;src: "{{ item }}"  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;dest: /tmp/  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;with\_fileglob: "files/tmp/{{ inventory\_hostname }}/\*.yaml"

---

<div class="post-metadata">

**Author:** ![cloos](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/cloos/32/7297_2.png) [@cloos](https://forum.ansible.com/u/cloos)\
**Post date:** [March 8, 2022, 2:20pm UTC](https://forum.ansible.com/t/how-to-stop-fileglob-lookup-warning-for-not-existing-paths/36410/3 "2022-03-08T14:20:10Z")

</div>

That’s not really a solution if I have 100 playbook hosts and 5 hosts where I will deploy files in this way.

---

<div class="post-metadata">

**Author:** ![cloos](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/cloos/32/7297_2.png) [@cloos](https://forum.ansible.com/u/cloos)\
**Post date:** [March 8, 2022, 2:34pm UTC](https://forum.ansible.com/t/how-to-stop-fileglob-lookup-warning-for-not-existing-paths/36410/4 "2022-03-08T14:34:50Z")

</div>

I was really surprised that wrapping the task in a block still gives me the warning for host **foo** :

- block:
- ansible.builtin.copy:  
src: “{{ item }}”  
dest: /tmp/  
with\_fileglob: “files/tmp/{{ inventory\_hostname }}/\*.yaml”  
when: inventory\_hostname == “bar”

I would expect here that the task (and the fileglob lookup) isn’t run for host **foo**.

---

<div class="post-metadata">

**Author:** ![vbotka](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/vbotka/32/359_2.png) [@vbotka](https://forum.ansible.com/u/vbotka)\
**Post date:** [March 8, 2022, 2:57pm UTC](https://forum.ansible.com/t/how-to-stop-fileglob-lookup-warning-for-not-existing-paths/36410/5 "2022-03-08T14:57:52Z")

</div>

In this case, it would be more efficient to select those 5 hosts  
instead of looping all 100.

---

<div class="post-metadata">

**Author:** ![cloos](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/cloos/32/7297_2.png) [@cloos](https://forum.ansible.com/u/cloos)\
**Post date:** [March 8, 2022, 5:10pm UTC](https://forum.ansible.com/t/how-to-stop-fileglob-lookup-warning-for-not-existing-paths/36410/6 "2022-03-08T17:10:35Z")

</div>

The above task is just a minimal example that shows my problem.  
This is actually used in my “one playbook to rule them all” and it doesn’t make sense to split this playbook in multiple ones.

I already know some not so nice workaround that maybe will suppress the warning.

I actually look for someone who shows me that I’m maybe missing something or telling me that this is a bug.  
Especially when wrapping the task in a block which still triggers the fileglob for hosts which doesn’t met the when condition sounds line a bug to me.

---

<div class="post-metadata">

**Author:** ![Philippe\_Kueck](https://avatars.discourse-cdn.com/v4/letter/p/e19b73/32.png) [@Philippe\_Kueck](https://forum.ansible.com/u/Philippe_Kueck)\
**Post date:** [March 8, 2022, 5:18pm UTC](https://forum.ansible.com/t/how-to-stop-fileglob-lookup-warning-for-not-existing-paths/36410/7 "2022-03-08T17:18:10Z")

</div>

Hi,

see [https://github.com/ansible/ansible/pull/47344](https://github.com/ansible/ansible/pull/47344)

I believe it's simply not wanted to avoid the warnings.

- Philippe

---

<div class="post-metadata">

**Author:** ![cloos](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/cloos/32/7297_2.png) [@cloos](https://forum.ansible.com/u/cloos)\
**Post date:** [March 8, 2022, 5:54pm UTC](https://forum.ansible.com/t/how-to-stop-fileglob-lookup-warning-for-not-existing-paths/36410/8 "2022-03-08T17:54:31Z")

</div>

Thanks Philippe for the PR link.  
I just thought about extending fileglob in this way.

---

<div class="post-metadata">

**Author:** ![vbotka](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/vbotka/32/359_2.png) [@vbotka](https://forum.ansible.com/u/vbotka)\
**Post date:** [March 9, 2022, 7:43am UTC](https://forum.ansible.com/t/how-to-stop-fileglob-lookup-warning-for-not-existing-paths/36410/9 "2022-03-09T07:43:44Z")

</div>

It's not a bug it's by design. In a loop, the condition is evaluated  
on each iteration. In your case, \*with\_fileglob\* must evaluate the  
list before the condition is applied.

\*block\* is irrelevant here. The condition is applied to all tasks.  
Try for example

&nbsp;&nbsp;&nbsp;&nbsp;- block:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;- debug:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;msg: OK1  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;- debug:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;msg: OK2  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;when: false

Instead of skipping the whole block the tasks will be skipped one by  
one.
