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

[email protected] schrieb am Dienstag, 8. März 2022 um 15:20:10 UTC+1:

> That's not really a solution if I have 100 playbook hosts and 5 hosts 
> where I will deploy files in this way.
> [email protected] schrieb am Dienstag, 8. März 2022 um 15:00:46 UTC+1:
>
>> On Tue, 8 Mar 2022 04:50:59 -0800 (PST) 
>> "[email protected]" <[email protected]> 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) 
>>
>> The simplest solution is to create empty directories if missing 
>>
>> - ansible.builtin.file: 
>> state: directory 
>> path: "files/tmp/{{ inventory_hostname }}" 
>> delegate_to: localhost 
>>
>> - ansible.builtin.copy: 
>> src: "{{ item }}" 
>> dest: /tmp/ 
>> with_fileglob: "files/tmp/{{ inventory_hostname }}/*.yaml" 
>>
>>
>> -- 
>> Vladimir Botka 
>>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/14f52f80-4d3b-4ede-b3af-32c241da2860n%40googlegroups.com.

Reply via email to