On Tue, 8 Mar 2022 06:34:50 -0800 (PST) "[email protected]" <[email protected]> wrote:
> 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
- block:
- debug:
msg: OK1
- debug:
msg: OK2
when: false
Instead of skipping the whole block the tasks will be skipped one by
one.
--
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/20220309084344.4c7d20b1%40gmail.com.
pgpOVSxJEJ2Qm.pgp
Description: OpenPGP digital signature
