Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

win_updates return values format differ if no update is found #307

Closed
Yannis100 opened this issue Nov 11, 2021 · 2 comments · Fixed by #308
Closed

win_updates return values format differ if no update is found #307

Yannis100 opened this issue Nov 11, 2021 · 2 comments · Fixed by #308

Comments

@Yannis100
Copy link

Yannis100 commented Nov 11, 2021

SUMMARY

The type of data in return_values.updates is not a dict ({}) if no updates were found, instead it's a list ([]), therefore dict2items Jinja filter returns an error instead of usually working if updates are found.

ISSUE TYPE
  • Bug Report
COMPONENT NAME

win_updates module

ANSIBLE VERSION
ansible [core 2.11.6]
  config file = /home/nimda/ansible/ansible.cfg
  configured module search path = ['/home/nimda/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /home/nimda/.local/lib/python3.8/site-packages/ansible
  ansible collection location = /home/nimda/.ansible/collections:/usr/share/ansible/collections
  executable location = /home/nimda/.local/bin/ansible
  python version = 3.8.10 (default, Sep 28 2021, 16:10:42) [GCC 9.3.0]
  jinja version = 2.10.1
  libyaml = True
COLLECTION VERSION
# /home/admin/.ansible/collections/ansible_collections
Collection      Version
--------------- -------
ansible.windows 1.8.0
CONFIGURATION
ANSIBLE_PIPELINING(/home/nimda/ansible/ansible.cfg) = True
CACHE_PLUGIN(/home/nimda/ansible/ansible.cfg) = jsonfile
CACHE_PLUGIN_CONNECTION(/home/nimda/ansible/ansible.cfg) = cache
CACHE_PLUGIN_TIMEOUT(/home/nimda/ansible/ansible.cfg) = 3600
DEFAULT_FORKS(/home/nimda/ansible/ansible.cfg) = 50
DEFAULT_GATHERING(/home/nimda/ansible/ansible.cfg) = smart
DEFAULT_GATHER_SUBSET(/home/nimda/ansible/ansible.cfg) = ['!config', '!hardware', '!interfaces']
DEFAULT_HOST_LIST(/home/nimda/ansible/ansible.cfg) = ['/home/nimda/ansible/inventory']
DEFAULT_TIMEOUT(/home/nimda/ansible/ansible.cfg) = 30
INVENTORY_CACHE_ENABLED(/home/nimda/ansible/ansible.cfg) = True
PARAMIKO_HOST_KEY_AUTO_ADD(/home/nimda/ansible/ansible.cfg) = True
PERSISTENT_COMMAND_TIMEOUT(/home/nimda/ansible/ansible.cfg) = 60
PERSISTENT_CONNECT_TIMEOUT(/home/nimda/ansible/ansible.cfg) = 60
RETRY_FILES_ENABLED(/home/nimda/ansible/ansible.cfg) = True
OS / ENVIRONMENT

Ubuntu 20.04, python 3.8.10

STEPS TO REPRODUCE
      - name: Install updates
        ansible.windows.win_updates:
          reject_list: "{{ blacklist_package | default(omit, true) }}"
          accept_list: "{{ whitelist_package | default(omit, true) }}"
          category_names:
          - CriticalUpdates
          - SecurityUpdates
          - Windows Server 2019
          state: installed
          log_path: c:\{{ inventory_hostname }}_updates.log
          reboot: yes
          reboot_timeout: 3600
        register: update_result

     - name: writing host and update to log
        shell: echo host:{{inventory_hostname}} ,title:{{ item.value.title }} ,kb number:{{ item.value.kb }} >> /path/to/log.txt
        loop: "{{ update_result.updates | dict2items }}"
        delegate_to: localhost
EXPECTED RESULTS
TASK [Update results] ***********************************************************************************************************************************************************************************************************************
ok: [srvfrtestwin] => {
    "update_result": {
        "changed": false,
        "failed": false,
        "failed_update_count": 0,
        "filtered_updates": [],
        "found_update_count": 0,
        "installed_update_count": 0,
        "reboot_required": false,
        "updates": {}
    }
}
ACTUAL RESULTS
TASK [Update results] ***********************************************************************************************************************************************************************************************************************
ok: [srvfrtestwin] => {
    "update_result": {
        "changed": false,
        "failed": false,
        "failed_update_count": 0,
        "filtered_updates": [],
        "found_update_count": 0,
        "installed_update_count": 0,
        "reboot_required": false,
        "updates": []
    }
}
ERROR! Unexpected templating type error occurred on ({{ update_result.updates | dict2items }}): dict2items requires a dictionary, got <class 'list'> instead.
@jborean93
Copy link
Collaborator

Wow I don't know how this went unnoticed but looks like both updates and filtered_updates are returning a list of dicts rather than the dict with the key being the update guid. This is a result of the large refactor on in 1.7.0 of this collection #225. Will have to fix that up so it returns the dict format that was used historically.

@jborean93
Copy link
Collaborator

Thanks for picking this up @Yannis100, I've opened #308 which should revert the return value back to what it was before.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants