loop: simplify dict2items example in docs (#66235)

* Added a simple example to explain "dict2items" filters for better understading.

Fixes: #65505

Signed-off-by: Abhijeet Kasurde <akasurde@redhat.com>
This commit is contained in:
Abhijeet Kasurde 2020-01-07 21:02:46 +05:30 committed by Sandra McCann
parent f8654de851
commit 469f104ec2
2 changed files with 8 additions and 8 deletions

View file

@ -0,0 +1,2 @@
minor_changes:
- Simplify dict2items filter example in loop documentation (https://github.com/ansible/ansible/issues/65505).

View file

@ -121,18 +121,16 @@ To loop over a dict, use the :ref:`dict2items <dict_filter>`:
.. code-block:: yaml .. code-block:: yaml
- name: create a tag dictionary of non-empty tags - name: Using dict2items
set_fact: debug:
tags_dict: "{{ (tags_dict|default({}))|combine({item.key: item.value}) }}" msg: "{{ item.key }} - {{ item.value }}"
loop: "{{ tags|dict2items }}" loop: "{{ tag_data | dict2items }}"
vars: vars:
tags: tag_data:
Environment: dev Environment: dev
Application: payment Application: payment
Another: "{{ doesnotexist|default() }}"
when: item.value != ""
Here, we don't want to set empty tags, so we create a dictionary containing only non-empty tags. Here, we are iterating over `tag_data` and printing the key and the value from it.
Registering variables with a loop Registering variables with a loop
================================= =================================