From 469f104ec27e99ea26d42685ba027fe03571fac9 Mon Sep 17 00:00:00 2001 From: Abhijeet Kasurde Date: Tue, 7 Jan 2020 21:02:46 +0530 Subject: [PATCH] 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 --- changelogs/fragments/dict2items.yml | 2 ++ docs/docsite/rst/user_guide/playbooks_loops.rst | 14 ++++++-------- 2 files changed, 8 insertions(+), 8 deletions(-) create mode 100644 changelogs/fragments/dict2items.yml diff --git a/changelogs/fragments/dict2items.yml b/changelogs/fragments/dict2items.yml new file mode 100644 index 00000000000..81f11a25456 --- /dev/null +++ b/changelogs/fragments/dict2items.yml @@ -0,0 +1,2 @@ +minor_changes: +- Simplify dict2items filter example in loop documentation (https://github.com/ansible/ansible/issues/65505). diff --git a/docs/docsite/rst/user_guide/playbooks_loops.rst b/docs/docsite/rst/user_guide/playbooks_loops.rst index b86ebacb076..7830edbef7c 100644 --- a/docs/docsite/rst/user_guide/playbooks_loops.rst +++ b/docs/docsite/rst/user_guide/playbooks_loops.rst @@ -121,18 +121,16 @@ To loop over a dict, use the :ref:`dict2items `: .. code-block:: yaml - - name: create a tag dictionary of non-empty tags - set_fact: - tags_dict: "{{ (tags_dict|default({}))|combine({item.key: item.value}) }}" - loop: "{{ tags|dict2items }}" + - name: Using dict2items + debug: + msg: "{{ item.key }} - {{ item.value }}" + loop: "{{ tag_data | dict2items }}" vars: - tags: + tag_data: Environment: dev 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 =================================