title: Extracting values from YAML into Jinja template for Ansible playbook
body: <p>I have a YAML file with content as like below:</p>
  <pre><code>cat ../../ansible/playbooks/vars/patching-config.yml
  ---
  patching_tag_name: &quot;Patching&quot;
  my_windows_patching:
    - {
        OS: &quot;WINDOWS&quot;,
        tag_value: &quot;myProdA&quot;,
        frequency: &quot;Month&quot;, #patching frequency. OneTime|Day|Hour|Week|Month|Minute
        interval: 1, #interval of the schedule.
        rebootSetting: &quot;never&quot;, #ifRequired|never|always
        PatchGroup: testA,
        startDate: &quot;2020-01-16T23:59:59Z&quot;,
        expiryDate: &quot;2020-02-16T23:59:59Z&quot;,
        duration: &quot;PT2H0M&quot;,
        timeZone: &quot;Australia/Sydney&quot;,
        updateClassifications: &quot;Critical,Important,Moderate&quot; 
      }
  </code></pre>
  <p>I want to extract the values of <strong>updateClassifications</strong> from above <strong>YML</strong> file in Jinja Template file <strong>MaintenanceWindow.yml.j2</strong></p>
  <pre><code>Resources:
    WindowsNonProdBaseline:
      Type: AWS::SSM::PatchBaseline
      Properties:
        Name: Windows-Non-Prod-Baseline
        Description: Baseline containing all updates approved for Windows instances
        OperatingSystem: {{ item.OS }}
        PatchGroups:
        - {{ item.PatchGroup }}
        ApprovalRules:
          PatchRules:
          - PatchFilterGroup:
              PatchFilters:
              - Values:
                # - Critical
                # - Important
                # - Moderate
                {% for item in item.updateClassifications %}
                  - {{ item }}
                {% endfor %}
  </code></pre>
  <p>I'm trying with the code described above, below one more time snippet:</p>
  <pre><code>              {% for item in item.updateClassifications %}
                  - {{ item }}
                {% endfor %}
  </code></pre>
  <p>I'm calling <strong>patching-config.yml</strong> in my <strong>tasks/main.yml</strong> as below</p>
  <pre><code>- include_vars: &quot;{{playbook_dir}}/vars/patching-config.yml&quot;
    ignore_errors: yes
  
  - name: create a cloudformation stack
    cloudformation:
      stack_name: &quot;New-Ansible-cloudformation&quot;
      state: &quot;present&quot;
      disable_rollback: true
      template_body: &quot;{{ lookup('template', '../../cloudformation/patching/MaintenanceWindow.yml.j2') }}&quot;
    with_items: &quot;{{ telstra_windows_patching }}&quot;
  </code></pre>
  <p>Finally, invoking role as below</p>
  <pre><code>cat ansible/playbooks/patching.yml
  ---
  - hosts: localhost
    roles:
      - patching-cf-ssm
  </code></pre>
  <p>Unfortunately, it is not working.</p>
  <p>Any lead shall be greatly appreciated.</p>