i installed the community kubernetes collection (https://galaxy.ansible.com/community/kubernetes)
run ansible-galaxy collection install community.kubernetes
on my ansible machine and have this task to use the module:
- name: Create a dashboard service accountkubernetes.core.k8s:kubeconfig: "{{ hostvars['master'].kubeconfig }}"state: presentresource_definition:kind: ServiceAccountapiVersion: v1metadata:name: admin-usernamespace: kubernetes-dashboard
and thats the output:
fatal: [master]: FAILED! => {"msg": "Could not find imported module support code for ansiblemodule. Looked for either AnsibleTurboModule.py or module.py"}
ansible version:
ansible 2.9.9config file = /home/xx/ansible/ansible.cfgconfigured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']ansible python module location = /usr/local/lib/python3.7/dist-packages/ansibleexecutable location = /usr/local/bin/ansiblepython version = 3.7.3 (default, Jan 22 2021, 20:04:44) [GCC 8.3.0]
OS:
PRETTY_NAME="Debian GNU/Linux 10 (buster)"NAME="Debian GNU/Linux"VERSION_ID="10"VERSION="10 (buster)"VERSION_CODENAME=busterID=debianHOME_URL="https://www.debian.org/"SUPPORT_URL="https://www.debian.org/support"BUG_REPORT_URL="https://bugs.debian.org/"
what do i need to fix this problem?
if you need more informations, let me know!
Best Answer
I had this issue as well. Tracked it down to having not very well documented dependencies. The new kubernetes.core ansible package has a number of dependencies. The error you are getting is because of the AnsibleTurbo package. Even though the playbook doesn't use it by default, there is a reference that is unsatisfied. The following need to be installed on the host where your playbook is run:
ansible-galaxy collection install community.kubernetesansible-galaxy collection install cloud.common
That should solve the core problem you are having. You may run into another, where the kuberentes python API package needs to be installed on the targets.
Note: depending on how you define your hosts, you'll only need to install the pip package if you are trying to interact with the k8s API through the defined host. Installing the package locally and telling the k8s module to use localhost as the target should result in success if you have your kubeconfig locally, pointing to the remote cluster.
Here is what I added to my playbook to get the k8s module to work with the remotes:
- name: ensure python3 is installedbecome: yesansible.builtin.package:name:- python3- python3-pipstate: present- name: install kubernetes pip packagepip:name: kubernetesstate: present