Ansible-test validate-modules sanity test: report 'bad' return values that cannot be accessed with Jinja's dot notation

If a module returns a return value values or items or keys, you cannot access it in playbooks and roles with Jinja’s dot notation since result.values will be the method of dict, which shadows the returned value.

validate-modules of ansible-core devel will now flag such return values with bad-return-value-key (PR). This can for example look like:

plugins/modules/ansible_galaxy_install.py:0:0: bad-return-value-key: Return value key '<path>' found in installed_collections should not be used for return values since it cannot be accessed with dot notation in Jinja
plugins/modules/ansible_galaxy_install.py:0:0: bad-return-value-key: Return value key '<path>' found in installed_roles should not be used for return values since it cannot be accessed with dot notation in Jinja
plugins/modules/gandi_livedns.py:0:0: bad-return-value-key: Return value key 'values' found in record should not be used for return values since it cannot be accessed with dot notation in Jinja
plugins/modules/interfaces_file.py:0:0: bad-return-value-key: Return value key 'post-up' found in ifaces -> ifaces -> eth0 should not be used for return values since it cannot be accessed with dot notation in Jinja
plugins/modules/interfaces_file.py:0:0: bad-return-value-key: Return value key 'pre-up' found in ifaces -> ifaces -> eth0 should not be used for return values since it cannot be accessed with dot notation in Jinja
plugins/modules/keycloak_realm_info.py:0:0: bad-return-value-key: Return value key 'account-service' found in realm_info should not be used for return values since it cannot be accessed with dot notation in Jinja
plugins/modules/keycloak_realm_info.py:0:0: bad-return-value-key: Return value key 'token-service' found in realm_info should not be used for return values since it cannot be accessed with dot notation in Jinja
plugins/modules/keycloak_realm_info.py:0:0: bad-return-value-key: Return value key 'tokens-not-before' found in realm_info should not be used for return values since it cannot be accessed with dot notation in Jinja
plugins/modules/keycloak_realm_keys_metadata_info.py:0:0: bad-return-value-key: Return value key 'keys' found in keys_metadata should not be used for return values since it cannot be accessed with dot notation in Jinja
plugins/modules/nosh.py:0:0: bad-return-value-key: Return value key 'Required-By' found in status should not be used for return values since it cannot be accessed with dot notation in Jinja
plugins/modules/nosh.py:0:0: bad-return-value-key: Return value key 'Stopped-By' found in status should not be used for return values since it cannot be accessed with dot notation in Jinja
plugins/modules/nosh.py:0:0: bad-return-value-key: Return value key 'Wanted-By' found in status should not be used for return values since it cannot be accessed with dot notation in Jinja
plugins/modules/omapi_host.py:0:0: bad-return-value-key: Return value key 'hardware-address' found in lease should not be used for return values since it cannot be accessed with dot notation in Jinja
plugins/modules/omapi_host.py:0:0: bad-return-value-key: Return value key 'hardware-type' found in lease should not be used for return values since it cannot be accessed with dot notation in Jinja
plugins/modules/omapi_host.py:0:0: bad-return-value-key: Return value key 'ip-address' found in lease should not be used for return values since it cannot be accessed with dot notation in Jinja

You can add validate-modules:bad-return-value-key to tests/sanity/ignore-2.21.txt (and newer versions of the file) to ignore these potential problems.

I’d recommend to plan to rename these return values, by first adding a new name, and then (some time later) deprecate the old name. (You can use data tagging for that; example of a helper module utils that gracefully handles older ansible-core versions.)

2 Likes