The sad output is the following, indicating that “item” is undefined in the loop.
TASK [debug] ***********************************************************************************************************************************************************************************************
fatal: [localhost]: FAILED! => {“msg”: “The task includes an option with an undefined variable. The error was: ‘item’ is undefined\n\nThe error appears to have been in ‘/home/nico2601/block.yml’: line 25, column 9, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n - block:\n - debug:\n ^ here\n\nexception type: <class ‘ansible.errors.AnsibleUndefinedVariable’>\nexception: ‘item’ is undefined”}
to retry, use: --limit @/home/nico2601/block.retry
What I want to do is ensuring that the user before the : is set only when the string that I’m looping over does contain :
What’s the right way to do it?
Thanks.
The sad output is the following, indicating that "item" is undefined in
the loop.
when is executing before the loop so that's the reason this will not work.
TASK [debug]
***********************************************************************************************************************************************************************************************
fatal: [localhost]: FAILED! => {"msg": "The task includes an option with an
undefined variable. The error was: 'item' is undefined\n\nThe error appears
to have been in '/home/nico2601/block.yml': line 25, column 9, but may\nbe
elsewhere in the file depending on the exact syntax problem.\n\nThe
offending line appears to be:\n\n - block:\n - debug:\n ^
here\n\nexception type: <class
'ansible.errors.AnsibleUndefinedVariable'>\nexception: 'item' is undefined"}
to retry, use: --limit @/home/nico2601/block.retry
What I want to do is ensuring that the user before the : is set only when
the string that I'm looping over does contain :
What's the right way to do it?
If you but the user code in a file and use include_tasks it will work.
You’ll note that this error is from the ‘debug’ task, which has neither a loop nor a ‘when’ clause. item is undefined because item has not been defined for that task.
If you were attempting to apply the loop to the entire block, that is not supported.