title: Ansible combine only combines last item
body: <p>I need to accomplish something similar to <a href="https://stackoverflow.com/questions/47882281/ansible-how-to-modify-a-variable-during-a-loop">Ansible, How to modify a variable during a loop?</a> and <a href="https://stackoverflow.com/questions/59363779/ansible-loop-and-update-dict">Ansible Loop and Update Dict</a>, however, I need to be able to combine two dictionaries that contain lists into a single dictionary.  One dictionary is stored in group_vars file and the other in host_vars:</p>
  <p>group_vars :</p>
  <pre><code>access_control:
    - source_address: &quot;10.0.0.1/24&quot;
      description: &quot;Test 1&quot;
    - source_address: &quot;11.0.0.1/24&quot;
      description: &quot;Test 2&quot;
    - source_address: &quot;12.0.0.1/24&quot;
      description: &quot;Test 3&quot;
  </code></pre>
  <p>host_vars:</p>
  <pre><code>access_control_id:
    - access_id: &quot;a01&quot;
    - access_id: &quot;a06&quot;
  </code></pre>
  <p>The desired result is that each access_control_id is applied to each of the access_control items:</p>
  <pre><code>&quot;combined_access_control&quot;: [
      {
        &quot;source_address&quot;: &quot;10.0.0.1/24&quot;
        &quot;description&quot;: &quot;Test 1&quot;
        &quot;access_id&quot;: &quot;a01&quot;
      },
      {
        &quot;source_address&quot;: &quot;10.0.0.1/24&quot;
        &quot;description&quot;: &quot;Test 1&quot;
        &quot;access_id&quot;: &quot;a06&quot;
      },
      {
        &quot;source_address&quot;: &quot;11.0.0.1/24&quot;
        &quot;description&quot;: &quot;Test 2&quot;
        &quot;access_id&quot;: &quot;a01&quot;
      },
      {
        &quot;source_address&quot;: &quot;11.0.0.1/24&quot;
        &quot;description&quot;: &quot;Test 2&quot;
        &quot;access_id&quot;: &quot;a06&quot;
      },
      {
        &quot;source_address&quot;: &quot;12.0.0.1/24&quot;
        &quot;description&quot;: &quot;Test 3&quot;
        &quot;access_id&quot;: &quot;a01&quot;
      },
      {
        &quot;source_address&quot;: &quot;12.0.0.1/24&quot;
        &quot;description&quot;: &quot;Test 3&quot;
        &quot;access_id&quot;: &quot;a06&quot;
      },
  ]
  </code></pre>
  <p>I thought that I would be able to use something like this:</p>
  <pre><code>- name: Combine variables into one dict
    set_fact:
      combined_access_control: &quot;{{ combined_access_control| default ([item.1]) + [ { 'access_id': item.1.access_id } ] }}&quot;
    loop: &quot;{{ access_control | product (access_control_id)| list }}&quot;
  </code></pre>
  <p>But I only get a dictionary with access_ids:</p>
  <pre><code>    &quot;combined_access_control&quot;: [
          {
              &quot;access_id&quot;: &quot;a01&quot;
          },
          {
              &quot;access_id&quot;: &quot;a06&quot;
          },
          {
              &quot;access_id&quot;: &quot;a01&quot;
          },
          {
              &quot;access_id&quot;: &quot;a06&quot;
          },
          {
              &quot;access_id&quot;: &quot;a01&quot;
          },
          {
              &quot;access_id&quot;: &quot;a06&quot;
          }
      ],
  </code></pre>