Just wonder what's stopping you from doing this:

---
- name: "Loop Iteration List"
hosts: localhost
vars:
my_list:
- nfs_prod_target_id: "Khan"
- nfs_prod_source_id: "Siddque"
tasks:
- name: "Connect to Isilon Device"
ansible.builtin.debug:
msg: "{{ item }}"
loop: "{{ my_list }}"


*Kosala*




On Mon, Jun 26, 2023 at 10:09 AM Todd Lewis <[email protected]> wrote:

> I believe the* loop:* values are evaluated first, before any iterations
> are performed, in which case any undefined variables in any of the* loop:*
> expressions will throw the error you see.
>
> This is probably a desirable behavior in general even though in this case
> you got caught by surprise.
>
> Here's a work-around that uses a sentinel value — and blatantly abuses "
> *omit*" for which I'm sure to be rightly scorned. :)
>
> *---**- name: "Loop Iteration List"**  hosts: localhost**  vars:**    
> nfs_prod_target_id: "Khan"**    nfs_prod_source_id: "Siddque"**  tasks:**    
> - name: "Connect to Isilon Device"**      ansible.builtin.debug:**        
> msg: "{{ item }}"**      when: item != omit**      loop:**        - "{{ 
> nfs_prod_source_id | d(omit) }}"**        - "{{ nfs_prod_target_id | d(omit) 
> }}"**        - "{{ nfs_dev_source_id | d(omit) }}"**        - "{{ 
> nfs_dev_target_id | d(omit) }}"*
>
> Cheers,
> --
> Todd
>
> On 6/23/23 3:09 PM, javed khan Siddque wrote:
>
> The below task is not working as expected.
> i am expecting it will print message for at least 2 times which is defined
> and skip rest 2.
>
>
> TASK [Connect to Isilon Device]
> ****************************************************************************************************
> skipping: [localhost]
>
>
>
> ---
> - name: "Loop Iteration List"
> hosts: localhost
> vars:
> nfs_prod_target_id: "Khan"
> nfs_prod_source_id: "Siddque"
> tasks:
> - name: "Connect to Isilon Device"
> ansible.builtin.debug:
> msg: "{{ item }}"
> when: item is defined
> loop:
> - "{{ nfs_prod_source_id }}"
> - "{{ nfs_prod_target_id }}"
> - "{{ nfs_dev_source_id }}"
> - "{{ nfs_dev_target_id }}"
> --
>
>
> --
> 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/2366dc40-c7cb-234d-9fdb-f5cc110141f3%40gmail.com
> <https://groups.google.com/d/msgid/ansible-project/2366dc40-c7cb-234d-9fdb-f5cc110141f3%40gmail.com?utm_medium=email&utm_source=footer>
> .
>

-- 
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/CAP7S5HaJENJ9b9N5xbC-qwd6V6vfkhH9g1WhLvrMLCFqMrNsNg%40mail.gmail.com.

Reply via email to