# Community.okd.k8s and kubernetes.core.k8s hang/get stuck indefinitely

**URL:** <https://forum.ansible.com/t/community-okd-k8s-and-kubernetes-core-k8s-hang-get-stuck-indefinitely/4821>\
**Category:** Get Help\
**Tags:** playbook, kubernetes, galaxy-ng\
**Created:** [April 8, 2024, 3:34pm UTC](https://forum.ansible.com/t/community-okd-k8s-and-kubernetes-core-k8s-hang-get-stuck-indefinitely/4821 "2024-04-08T15:34:51Z")\
**Posts on this page:** 7\
**Page:** 2

<div class="post-metadata">

**Author:** ![Denney-tech](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/denney-tech/32/1556_2.png) [@Denney-tech](https://forum.ansible.com/u/Denney-tech)\
**Post date:** [April 10, 2024, 11:55pm UTC](https://forum.ansible.com/t/community-okd-k8s-and-kubernetes-core-k8s-hang-get-stuck-indefinitely/4821/21 "2024-04-10T23:55:06Z")

</div>

I was thinking the kubernetes\>=24.2.0 might be the issue this time, not jsonpatch. Something in the kubernetes pip package is calling yaml.load() and failing the module, so that was why I thought that might the problem.

---

<div class="post-metadata">

**Author:** ![123232455](https://avatars.discourse-cdn.com/v4/letter/1/a87d85/32.png) [@123232455](https://forum.ansible.com/u/123232455)\
**Post date:** [April 11, 2024, 8:47am UTC](https://forum.ansible.com/t/community-okd-k8s-and-kubernetes-core-k8s-hang-get-stuck-indefinitely/4821/22 "2024-04-11T08:47:26Z")

</div>

Hi, that was a good point. I’ve now tried with three different kubernetes versions:

- kubernetes-22.6.0
- kubernetes-24.2.0
- kubernetes-29.0.0

and the issue was persistent. playbook still hangs at community.okd.k8s unfortunately 😕

---

<div class="post-metadata">

**Author:** ![123232455](https://avatars.discourse-cdn.com/v4/letter/1/a87d85/32.png) [@123232455](https://forum.ansible.com/u/123232455)\
**Post date:** [April 11, 2024, 12:08pm UTC](https://forum.ansible.com/t/community-okd-k8s-and-kubernetes-core-k8s-hang-get-stuck-indefinitely/4821/23 "2024-04-11T12:08:27Z")

</div>

@Denney-tech I’d like to mention again that I think issue is with `ansible-core` as that is the only package I couldn’t install an older version of.

---

<div class="post-metadata">

**Author:** ![Denney-tech](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/denney-tech/32/1556_2.png) [@Denney-tech](https://forum.ansible.com/u/Denney-tech)\
**Post date:** [April 11, 2024, 2:30pm UTC](https://forum.ansible.com/t/community-okd-k8s-and-kubernetes-core-k8s-hang-get-stuck-indefinitely/4821/24 "2024-04-11T14:30:34Z")

</div>

Okay, so I split the newlines from your actual error output earlier. It’s the python3.8/ansible2.13.3 output, so it wouldn’t hurt to double-check what you’re getting now.

On to the output:

```auto
/usr/lib/python3/dist-packages/kubernetes/config/kube_config.py:434: YAMLLoadWarning: calling yaml.load() without Loader=... is deprecated, as the default Loader is unsafe. Please read https://msg.pyyaml.org/load for full details.
  config_dict=yaml.load(f),
Traceback (most recent call last):
  File "/home/user1/.ansible/tmp/ansible-tmp-1712652899.1646488-422-100298754495323/AnsiballZ_k8s.py", line 107, in <module>
    _ansiballz_main()
  File "/home/user1/.ansible/tmp/ansible-tmp-1712652899.1646488-422-100298754495323/AnsiballZ_k8s.py", line 99, in _ansiballz_main
    invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)
  File "/home/user1/.ansible/tmp/ansible-tmp-1712652899.1646488-422-100298754495323/AnsiballZ_k8s.py", line 47, in invoke_module
    runpy.run_module(mod_name='ansible_collections.community.okd.plugins.modules.k8s', init_globals=dict(_module_fqn='ansible_collections.community.okd.plugins.modules.k8s', _modlib_path=modlib_path),
  File "/usr/lib/python3.8/runpy.py", line 207, in run_module
    return _run_module_code(code, init_globals, run_name, mod_spec)
  File "/usr/lib/python3.8/runpy.py", line 97, in _run_module_code
    _run_code(code, mod_globals, init_globals,
  File "/usr/lib/python3.8/runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "/tmp/ansible_community.okd.k8s_payload_j5r7uimp/ansible_community.okd.k8s_payload.zip/ansible_collections/community/okd/plugins/modules/k8s.py", line 323, in <module>
  File "/tmp/ansible_community.okd.k8s_payload_j5r7uimp/ansible_community.okd.k8s_payload.zip/ansible_collections/community/okd/plugins/modules/k8s.py", line 314, in main
  File "/tmp/ansible_community.okd.k8s_payload_j5r7uimp/ansible_community.okd.k8s_payload.zip/ansible_collections/community/okd/plugins/module_utils/k8s.py", line 44, in __init__
  File "/tmp/ansible_community.okd.k8s_payload_j5r7uimp/ansible_community.okd.k8s_payload.zip/ansible_collections/community/okd/plugins/module_utils/openshift_common.py", line 49, in __init__
  File "/tmp/ansible_community.okd.k8s_payload_j5r7uimp/ansible_community.okd.k8s_payload.zip/ansible_collections/kubernetes/core/plugins/module_utils/k8s/client.py", line 352, in get_api_client
  File "/tmp/ansible_community.okd.k8s_payload_j5r7uimp/ansible_community.okd.k8s_payload.zip/ansible_collections/kubernetes/core/plugins/module_utils/k8s/client.py", line 246, in wrapper
  File "/tmp/ansible_community.okd.k8s_payload_j5r7uimp/ansible_community.okd.k8s_payload.zip/ansible_collections/kubernetes/core/plugins/module_utils/k8s/client.py", line 259, in create_api_client
NameError: name 'k8sdynamicclient' is not defined

```

The last line I think is important. `k8sdynamicclient` was introduced in kubernetes.core==2.0.0 collection.

> <https://github.com/ansible-collections/kubernetes.core/blob/2.0.0/plugins/module_utils/k8sdynamicclient.py>

If you run `ansible-galaxy collection list kubernetes.core` do you have multiple versions listed? If you have anything older than 2.0.0, remove them and try again.

---

<div class="post-metadata">

**Author:** ![123232455](https://avatars.discourse-cdn.com/v4/letter/1/a87d85/32.png) [@123232455](https://forum.ansible.com/u/123232455)\
**Post date:** [April 15, 2024, 4:35pm UTC](https://forum.ansible.com/t/community-okd-k8s-and-kubernetes-core-k8s-hang-get-stuck-indefinitely/4821/25 "2024-04-15T16:35:47Z")

</div>

Hi,

Thank you for the comment. I managed to fix the issue. The token variable needed to be `okd_auth.openshift_auth.api_key` and referenced like this:

```auto
    - name: Create a k8s namespace
      community.okd.k8s:
        api_key: "{{ okd_auth.openshift_auth.api_key }}"

```

This was certainly an error I needed to fix but it wasn’t the root cause. The root cause was me not setting up the environment properly. I’ve now added the `ansible_python_interpreter` variable to point to python binary inside the virtual environment, removed all the ‘supporting python packages’ that were installed outside of the virtual environment and that basically fixed it for me.

There were some python packages that were not installed within the environment and ansible was picking them from outside the environment. And that caused the issue apparently.

Apologies for taking up your time and thank you for your support.

---

<div class="post-metadata">

**Author:** ![Denney-tech](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/denney-tech/32/1556_2.png) [@Denney-tech](https://forum.ansible.com/u/Denney-tech)\
**Post date:** [April 15, 2024, 4:39pm UTC](https://forum.ansible.com/t/community-okd-k8s-and-kubernetes-core-k8s-hang-get-stuck-indefinitely/4821/26 "2024-04-15T16:39:50Z")

</div>

Glad you figured it out. We definitely got error blind trying to troubleshoot your python/collection dependency issues to miss that the api\_key was using a literal string instead of the variable.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/ansible/original/1X/1882d9a01da5d8996a862359b0913cc568a39b84.svg) [@system](https://forum.ansible.com/u/system)\
**Post date:** [May 15, 2024, 4:39pm UTC](https://forum.ansible.com/t/community-okd-k8s-and-kubernetes-core-k8s-hang-get-stuck-indefinitely/4821/27 "2024-05-15T16:39:56Z")

</div>

Closed on May 15, 2024, 4:39pm UTC

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.

[Previous page](https://forum.ansible.com/t/community-okd-k8s-and-kubernetes-core-k8s-hang-get-stuck-indefinitely/4821.md?page=1)
