You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The k8s_json_patch module is failing with the error: AttributeError: 'K8sAnsibleMixin' object has no attribute 'fail_json'
I found issue #433 which has the same error with the k8s_info module which was fixed in version 2.3.0. However, I'm using version 2.3.1 of the collection.
The playbook is targeting localhost as the host and is running inside an execution environment. The target is a Red Hat OpenShift cluster.
STEPS TO REPRODUCE
When the below task is run against an OpenShift cluster with the namespace created and the ansible-automation-platform operator installed it will fail (its missing setting the apiversion). Although there is a failure to find the object to patch due to the missing apiversion setting the module fails with the `no attribute 'fail_json' which is unexpected.
The task fails but without the module failing with the traceback. The No matches found for {'prefix': None, 'api_version': 'v1', 'short_names': ['Subscription']} message should be reported for the task.
ACTUAL RESULTS
Module fails with a traceback.
TASK [redhat_cop.aap_utilities.aap_ocp_install : Update install plan] **********************************************************************************************
task path: /home/runner/.ansible/collections/ansible_collections/redhat_cop/aap_utilities/roles/aap_ocp_install/tasks/install-operator.yml:34
<127.0.0.1> ESTABLISH LOCAL CONNECTION FOR USER: root
<127.0.0.1> EXEC /bin/sh -c 'echo ~root && sleep 0'
<127.0.0.1> EXEC /bin/sh -c '( umask 77 && mkdir -p "` echo /root/.ansible/tmp `"&& mkdir "` echo /root/.ansible/tmp/ansible-tmp-1660064438.7171547-176-132998062341796 `" && echo ansible-tmp-1660064438.7171547-176-132998062341796="` echo /root/.ansible/tmp/ansible-tmp-1660064438.7171547-176-132998062341796 `" ) && sleep 0'
Using module file /usr/share/ansible/collections/ansible_collections/kubernetes/core/plugins/modules/k8s_json_patch.py
<127.0.0.1> PUT /home/runner/.ansible/tmp/ansible-local-64bu1g3mwc/tmpvkm_6gg4 TO /root/.ansible/tmp/ansible-tmp-1660064438.7171547-176-132998062341796/AnsiballZ_k8s_json_patch.py
<127.0.0.1> EXEC /bin/sh -c 'chmod u+x /root/.ansible/tmp/ansible-tmp-1660064438.7171547-176-132998062341796/ /root/.ansible/tmp/ansible-tmp-1660064438.7171547-176-132998062341796/AnsiballZ_k8s_json_patch.py && sleep 0'
<127.0.0.1> EXEC /bin/sh -c '/usr/bin/python3 /root/.ansible/tmp/ansible-tmp-1660064438.7171547-176-132998062341796/AnsiballZ_k8s_json_patch.py && sleep 0'
<127.0.0.1> EXEC /bin/sh -c 'rm -f -r /root/.ansible/tmp/ansible-tmp-1660064438.7171547-176-132998062341796/ > /dev/null 2>&1 && sleep 0'
The full traceback is:
Traceback (most recent call last):
File "/tmp/ansible_kubernetes.core.k8s_json_patch_payload_otle065i/ansible_kubernetes.core.k8s_json_patch_payload.zip/ansible_collections/kubernetes/core/plugins/module_utils/common.py", line 388, in find_resource
File "/tmp/ansible_kubernetes.core.k8s_json_patch_payload_otle065i/ansible_kubernetes.core.k8s_json_patch_payload.zip/ansible_collections/kubernetes/core/plugins/module_utils/common.py", line 365, in _find_resource_with_prefix
File "/tmp/ansible_kubernetes.core.k8s_json_patch_payload_otle065i/ansible_kubernetes.core.k8s_json_patch_payload.zip/ansible_collections/kubernetes/core/plugins/module_utils/client/discovery.py", line 182, in get
kubernetes.dynamic.exceptions.ResourceNotFoundError: No matches found for {'prefix': None, 'api_version': 'v1', 'short_names': ['Subscription']}
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/root/.ansible/tmp/ansible-tmp-1660064438.7171547-176-132998062341796/AnsiballZ_k8s_json_patch.py", line 107, in <module>
_ansiballz_main()
File "/root/.ansible/tmp/ansible-tmp-1660064438.7171547-176-132998062341796/AnsiballZ_k8s_json_patch.py", line 99, in _ansiballz_main
invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)
File "/root/.ansible/tmp/ansible-tmp-1660064438.7171547-176-132998062341796/AnsiballZ_k8s_json_patch.py", line 47, in invoke_module
runpy.run_module(mod_name='ansible_collections.kubernetes.core.plugins.modules.k8s_json_patch', init_globals=dict(_module_fqn='ansible_collections.kubernetes.core.plugins.modules.k8s_json_patch', _modlib_path=modlib_path),
File "/usr/lib64/python3.8/runpy.py", line 207, in run_module
return _run_module_code(code, init_globals, run_name, mod_spec)
File "/usr/lib64/python3.8/runpy.py", line 97, in _run_module_code
_run_code(code, mod_globals, init_globals,
File "/usr/lib64/python3.8/runpy.py", line 87, in _run_code
exec(code, run_globals)
File "/tmp/ansible_kubernetes.core.k8s_json_patch_payload_otle065i/ansible_kubernetes.core.k8s_json_patch_payload.zip/ansible_collections/kubernetes/core/plugins/modules/k8s_json_patch.py", line 287, in <module>
File "/tmp/ansible_kubernetes.core.k8s_json_patch_payload_otle065i/ansible_kubernetes.core.k8s_json_patch_payload.zip/ansible_collections/kubernetes/core/plugins/modules/k8s_json_patch.py", line 283, in main
File "/tmp/ansible_kubernetes.core.k8s_json_patch_payload_otle065i/ansible_kubernetes.core.k8s_json_patch_payload.zip/ansible_collections/kubernetes/core/plugins/modules/k8s_json_patch.py", line 212, in execute_module
File "/tmp/ansible_kubernetes.core.k8s_json_patch_payload_otle065i/ansible_kubernetes.core.k8s_json_patch_payload.zip/ansible_collections/kubernetes/core/plugins/module_utils/common.py", line 391, in find_resource
File "/tmp/ansible_kubernetes.core.k8s_json_patch_payload_otle065i/ansible_kubernetes.core.k8s_json_patch_payload.zip/ansible_collections/kubernetes/core/plugins/module_utils/common.py", line 566, in fail
AttributeError: 'K8sAnsibleMixin' object has no attribute 'fail_json'
fatal: [localhost]: FAILED! => {
"changed": false,
"module_stderr": "Traceback (most recent call last):\n File \"/tmp/ansible_kubernetes.core.k8s_json_patch_payload_otle065i/ansible_kubernetes.core.k8s_json_patch_payload.zip/ansible_collections/kubernetes/core/plugins/module_utils/common.py\", line 388, in find_resource\n File \"/tmp/ansible_kubernetes.core.k8s_json_patch_payload_otle065i/ansible_kubernetes.core.k8s_json_patch_payload.zip/ansible_collections/kubernetes/core/plugins/module_utils/common.py\", line 365, in _find_resource_with_prefix\n File \"/tmp/ansible_kubernetes.core.k8s_json_patch_payload_otle065i/ansible_kubernetes.core.k8s_json_patch_payload.zip/ansible_collections/kubernetes/core/plugins/module_utils/client/discovery.py\", line 182, in get\nkubernetes.dynamic.exceptions.ResourceNotFoundError: No matches found for {'prefix': None, 'api_version': 'v1', 'short_names': ['Subscription']}\n\nDuring handling of the above exception, another exception occurred:\n\nTraceback (most recent call last):\n File \"/root/.ansible/tmp/ansible-tmp-1660064438.7171547-176-132998062341796/AnsiballZ_k8s_json_patch.py\", line 107, in <module>\n _ansiballz_main()\n File \"/root/.ansible/tmp/ansible-tmp-1660064438.7171547-176-132998062341796/AnsiballZ_k8s_json_patch.py\", line 99, in _ansiballz_main\n invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)\n File \"/root/.ansible/tmp/ansible-tmp-1660064438.7171547-176-132998062341796/AnsiballZ_k8s_json_patch.py\", line 47, in invoke_module\n runpy.run_module(mod_name='ansible_collections.kubernetes.core.plugins.modules.k8s_json_patch', init_globals=dict(_module_fqn='ansible_collections.kubernetes.core.plugins.modules.k8s_json_patch', _modlib_path=modlib_path),\n File \"/usr/lib64/python3.8/runpy.py\", line 207, in run_module\n return _run_module_code(code, init_globals, run_name, mod_spec)\n File \"/usr/lib64/python3.8/runpy.py\", line 97, in _run_module_code\n _run_code(code, mod_globals, init_globals,\n File \"/usr/lib64/python3.8/runpy.py\", line 87, in _run_code\n exec(code, run_globals)\n File \"/tmp/ansible_kubernetes.core.k8s_json_patch_payload_otle065i/ansible_kubernetes.core.k8s_json_patch_payload.zip/ansible_collections/kubernetes/core/plugins/modules/k8s_json_patch.py\", line 287, in <module>\n File \"/tmp/ansible_kubernetes.core.k8s_json_patch_payload_otle065i/ansible_kubernetes.core.k8s_json_patch_payload.zip/ansible_collections/kubernetes/core/plugins/modules/k8s_json_patch.py\", line 283, in main\n File \"/tmp/ansible_kubernetes.core.k8s_json_patch_payload_otle065i/ansible_kubernetes.core.k8s_json_patch_payload.zip/ansible_collections/kubernetes/core/plugins/modules/k8s_json_patch.py\", line 212, in execute_module\n File \"/tmp/ansible_kubernetes.core.k8s_json_patch_payload_otle065i/ansible_kubernetes.core.k8s_json_patch_payload.zip/ansible_collections/kubernetes/core/plugins/module_utils/common.py\", line 391, in find_resource\n File \"/tmp/ansible_kubernetes.core.k8s_json_patch_payload_otle065i/ansible_kubernetes.core.k8s_json_patch_payload.zip/ansible_collections/kubernetes/core/plugins/module_utils/common.py\", line 566, in fail\nAttributeError: 'K8sAnsibleMixin' object has no attribute 'fail_json'\n",
"module_stdout": "",
"msg": "MODULE FAILURE\nSee stdout/stderr for the exact error",
"rc": 1
}
The text was updated successfully, but these errors were encountered:
The module isn't always returning a module error. I did another test where I set the apiversion, kind, namespace, and name, but the name was not the name of an existing object and the task correctly failed, but the module did not.
SUMMARY
The
k8s_json_patch
module is failing with the error:AttributeError: 'K8sAnsibleMixin' object has no attribute 'fail_json'
I found issue #433 which has the same error with the
k8s_info
module which was fixed in version 2.3.0. However, I'm using version 2.3.1 of the collection.ISSUE TYPE
COMPONENT NAME
k8s_json_patch
ANSIBLE VERSION
COLLECTION VERSION
CONFIGURATION
OS / ENVIRONMENT
The playbook is targeting
localhost
as the host and is running inside an execution environment. The target is a Red Hat OpenShift cluster.STEPS TO REPRODUCE
When the below task is run against an OpenShift cluster with the namespace created and the ansible-automation-platform operator installed it will fail (its missing setting the
apiversion
). Although there is a failure to find the object to patch due to the missingapiversion
setting the module fails with the `no attribute 'fail_json' which is unexpected.EXPECTED RESULTS
The task fails but without the module failing with the traceback. The
No matches found for {'prefix': None, 'api_version': 'v1', 'short_names': ['Subscription']}
message should be reported for the task.ACTUAL RESULTS
Module fails with a traceback.
The text was updated successfully, but these errors were encountered: