Uploaded image for project: 'Product Technical Learning'
  1. Product Technical Learning
  2. PTL-13940

with_items does not auto-flatten as suggested by the student guide

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: Minor Minor
    • None
    • None
    • DO374
    • None
    • False
    • Hide

      None

      Show
      None
    • False
    • en-US (English)

      Please fill in the following information:


      URL: https://rol.redhat.com/rol/app/courses/do374-2.2/pages/ch07s05
      Reporter RHNID: atcorduneanu@extraordy.com
      Section Title:    h4. Iterating over a List of Lists                                                                    

      Issue description

      The student guide suggests that with_items performs one-level flattening of its lists.

      I tried to reproduce to show to my delegates, but I couldn't

      Steps to reproduce:

       

      ---
      - hosts: all
        gather_facts: false
        tasks:
          - set_fact:
              lista1: "{{ [1, 2, [3, 4, [5]], 6] }}"
              lista2: "{{ [7, 8, [9]] }}"
      
          - name: "with_items task"
            debug:
              msg: "{{ item }}"
            with_items: 
              - "{{ lista1 }}"
              - "{{ lista2 }}"
      
          - name: "loop task"
            debug:
              msg: "{{ item }}"
            loop: "{{ (lista1 | flatten) + (lista2 | flatten) }}" 

      The playbook above shows how the first debug task (with_items task) does not iterate on a flat list, but the second does (loop task)

       

      Workaround:

      using loop keyword instead of with_items..

      Expected result:

      {}I would expect the student guide to be corrected on the paragraph:

      "The with_items keyword combines these three lists into a single list containing the entries from all three lists. It automatically performs one-level flattening of its list"

      or more context provided. Or a reference to an example and documentation attached to this issue, in the case that I'm wrong.

              glsbugs-automation@redhat.com PTL - Ansible Team
              atcorduneanu@extraordy.com Andrei Tudor Corduneanu
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

                Created:
                Updated: