On Monday, February 26, 2018 at 9:39:10 AM UTC-5, Nico Sabbi wrote:
>
> HI,
> can I combine when: and with_items clauses as in this example?
>
> become: true
> become_user: root
> tasks:
> - block:
> - debug:
> msg: "riga {{item}}"
> - user:
> name: "{{ item.split(':')[0] }}"
> home: "{{ item.split(':')[1] }}"
> when: item search(":")
> with_items: [ "abc:def", "yyy.zzz"]
>
> 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
>
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.
--
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 post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/ansible-project/2a1feab4-0efc-400e-94c4-079433d09a29%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.