# Playbook Variable and Jinja 2 -- Namespace Problem?

**URL:** <https://forum.ansible.com/t/playbook-variable-and-jinja-2-namespace-problem/35905>\
**Category:** Ansible Project\
**Tags:** windows\
**Created:** [October 20, 2021, 5:25pm UTC](https://forum.ansible.com/t/playbook-variable-and-jinja-2-namespace-problem/35905 "2021-10-20T17:25:36Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![John-Paul\_Pagano](https://avatars.discourse-cdn.com/v4/letter/j/b782af/32.png) [@John-Paul\_Pagano](https://forum.ansible.com/u/John-Paul_Pagano)\
**Post date:** [October 20, 2021, 5:25pm UTC](https://forum.ansible.com/t/playbook-variable-and-jinja-2-namespace-problem/35905/1 "2021-10-20T17:25:36Z")

</div>

ansible-playbook [core 2.11.5]  
python version = 3.9.7 (default, Sep 3 2021, 12:45:31) [Clang 12.0.0 (clang-1200.0.32.29)]  
jinja version = 2.11.3

Hi,

I’m trying to write a play that will connect to a managed Windows node, gather a list of Windows Updates that are available to be installed on it, and output that list to stdout. Below is what I’ve cobbled together, but it doesn’t fully work. While the list is dumped as expected to the local file “win\_updates.log”, it is not also copied to stdout. The error I get is “msg”: “The task includes an option with an undefined variable. The error was: list object has no element”.

It appears that the ‘k’ variable in the for loop in the Jinja 2 routine is unset, presumably because the “update\_results” variable in the play isn’t available to it. Can you help me understand what I’m doing wrong?

Thanks!

- name: List all updates that might be installed  
hosts: all

tasks:

- name: Find possible updates  
become: true  
become\_method: runas  
become\_user: SYSTEM  
win\_updates:  
category\_names: ‘\*’  
state: searched  
log\_path: C:/Users/MY\_USER/win\_updates.log  
register: update\_results

- debug:

msg: |  
{% for k in update\_results.updates %}  
{{ update\_results.updates[k].title }}  
{% endfor %}

---

<div class="post-metadata">

**Author:** ![Clint\_Denham](https://avatars.discourse-cdn.com/v4/letter/c/919ad9/32.png) [@Clint\_Denham](https://forum.ansible.com/u/Clint_Denham)\
**Post date:** [October 20, 2021, 10:47pm UTC](https://forum.ansible.com/t/playbook-variable-and-jinja-2-namespace-problem/35905/2 "2021-10-20T22:47:57Z")

</div>

Can you post a little of update\_results?

Sometimes with this error you just need to include the list reference. 0 being the first list.

update\_results.0.updstes[k]

Once we get the entire update\_results we can see for sure.

---

<div class="post-metadata">

**Author:** ![Ryan\_Caudle](https://avatars.discourse-cdn.com/v4/letter/r/22d042/32.png) [@Ryan\_Caudle](https://forum.ansible.com/u/Ryan_Caudle)\
**Post date:** [October 20, 2021, 10:55pm UTC](https://forum.ansible.com/t/playbook-variable-and-jinja-2-namespace-problem/35905/3 "2021-10-20T22:55:18Z")

</div>

I thought we were on Jinja 3?

---

<div class="post-metadata">

**Author:** ![John-Paul\_Pagano](https://avatars.discourse-cdn.com/v4/letter/j/b782af/32.png) [@John-Paul\_Pagano](https://forum.ansible.com/u/John-Paul_Pagano)\
**Post date:** [October 21, 2021, 12:13am UTC](https://forum.ansible.com/t/playbook-variable-and-jinja-2-namespace-problem/35905/4 "2021-10-21T00:13:00Z")

</div>

Sorry, i probably should have done that. Here’s the output from a managed node that was left behind on patches for the purpose of testing.

ok: [MY\_IP] =\> {  
“update\_results.updates”: [  
{  
“categories”: [  
“Definition Updates”,  
“Microsoft Defender Antivirus”  
],  
“downloaded”: true,  
“id”: “971038cc-9d05-4a4c-9c53-51110f6b525a”,  
“installed”: true,  
“kb”: [  
“2267602”  
],  
“title”: “Security Intelligence Update for Microsoft Defender Antivirus - KB2267602 (Version 1.351.755.0)”  
},  
{  
“categories”: [  
“Update Rollups”,  
“Windows Server 2016”,  
“Windows Server 2019”  
],  
“downloaded”: true,  
“id”: “3af26db7-4c87-4c6e-ba44-5fa00913995e”,  
“installed”: true,  
“kb”: [  
“890830”  
],  
“title”: “Windows Malicious Software Removal Tool x64 - v5.94 (KB890830)”  
},  
{  
“categories”: [  
“Security Updates”,  
“Windows Server 2016”  
],  
“downloaded”: true,  
“id”: “ff623435-c638-4c25-a907-843fa16c22b3”,  
“installed”: true,  
“kb”: [  
“5006669”  
],  
“title”: “2021-10 Cumulative Update for Windows Server 2016 for x64-based Systems (KB5006669)”  
},  
{  
“categories”: [  
“Feature Packs”,  
“Silverlight”  
],  
“downloaded”: true,  
“id”: “ca3bb521-a8ea-4e26-a563-2ad6e3108b9a”,  
“installed”: true,  
“kb”: [  
“4481252”  
],  
“title”: “Microsoft Silverlight (KB4481252)”  
},  
{  
“categories”: [  
“Definition Updates”,  
“Microsoft Defender Antivirus”  
],  
“downloaded”: true,  
“id”: “f6a66dbc-2311-4ee0-ad24-2392dbf48641”,  
“installed”: true,  
“kb”: [  
“2267602”  
],  
“title”: “Security Intelligence Update for Microsoft Defender Antivirus - KB2267602 (Version 1.351.759.0)”  
},  
{  
“categories”: [  
“Security Updates”,  
“Windows Server 2016”  
],  
“downloaded”: true,  
“id”: “73f45b23-8537-455d-83fd-840e7e93b835”,  
“installed”: true,  
“kb”: [  
“5005698”  
],  
“title”: “2021-09 Servicing Stack Update for Windows Server 2016 for x64-based Systems (KB5005698)”  
}  
]  
}

---

<div class="post-metadata">

**Author:** ![John-Paul\_Pagano](https://avatars.discourse-cdn.com/v4/letter/j/b782af/32.png) [@John-Paul\_Pagano](https://forum.ansible.com/u/John-Paul_Pagano)\
**Post date:** [October 21, 2021, 12:18am UTC](https://forum.ansible.com/t/playbook-variable-and-jinja-2-namespace-problem/35905/5 "2021-10-21T00:18:47Z")

</div>

Do you recommend upgrading to Jinja2 3.x for my version of Ansible?
