I believe it's simply not wanted to avoid the warnings.
- Philippe
On 08.03.22 13:50, cl...@netsandbox.de wrote:
> 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?
>
> 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*.
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