On Wed, 22 Jan 2020 21:58:14 -0800 (PST)
Rakesh Parida <[email protected]> wrote:

> > - hosts: localhost
> >   tasks:
> >     - name: Create a list
> >       set_fact:
> >          some_value:
> >             - avenger
> >             - mk11
> >             - witcher
> >             - gow
> >             - saintsrow
> >
> >     - debug:
> >         msg: "{{ some_value }}"
> >
> >     - name: Print avenger
> >       set_fact:
> >         avenger_record: "{{ item }}"
> >       when: item is defined and item  == 'avenger'
> >       with_items: "{{ somevalue }}"

The name of the variable is 'some_value'. Correct other references as well

          with_items: "{{ some_value }}"

> > [...]
> >     - name: Display Lists
> >       debug:
> >         msg: "{{ item }}"
> >       with_items:
> >          - "{ best_fav  }}"
> >          - "{{ good_fav }}"
> >          - "{{ better_fav }}"
> >       when: item != None

Balance the braces. Correct

          with_items:
            - "{{ best_fav }}"

Notes:

* Use 'loop' instead of 'with_items'. See
  
https://docs.ansible.com/ansible/latest/porting_guides/porting_guide_2.5.html#migrating-from-with-x-to-loop
* The variable 'item' is always defined in a loop (when not explicitly
  renamed). The condition 'when: item is defined ...' is redundant. It is
  enough to test e.g. 'when: item  == "avenger"'
* The condition 'when: item != None' in the last task is also redundant. An
  iteration will be skipped if the list is empty.
* Give a try to 'ansible-lint' and 'yamllint'

HTH,

        -vlado

-- 
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/20200123091648.7107ee51%40gmail.com.

Attachment: pgphjfkgxiWLO.pgp
Description: OpenPGP digital signature

Reply via email to