Hi everybody,
following this bug [1] I’ve opened yesterday and the suggestion from Brian I want to understand in depth what is considered by design inside Ansible about “when”.
Now, leaving aside the usage of “when” inside roles, let’s start with this simple example:
`
TASK [bug_20919_bis : Configure key on remote host] ****************************
task path: /home/rasca/Red-Hat/ansible/tests/roles/bug_20919_bis/tasks/main.yml:12
[WARNING]: Unable to find ‘rasca.pub’ in expected paths.
File lookup using None as file
fatal: [192.168.122.100]: FAILED! => {
“failed”: true,
“msg”: “could not locate file in lookup: rasca.pub”
}
to retry, use: --limit @/home/rasca/Red-Hat/ansible/tests/bug_20919_bis.retry
`
So the problem here does not seem to be related at what is inside the variable passed to “with_file”, but to the fact that independently from what’s passed and from the “when:” variable, ansible looks for the file.
The with_ section gets executed BEFORE the when, so you cannot use
when to avoid the with_ from being evaluated, the when runs once per
item (inside the with_ loop) to allow the task to be conditional PER
ITEM.