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 %}