kubernetes.core.helm throwing Invalid Syntax

Hi team,

I’m running ansible on centos 7 in which python 2 coming by default and some dependencies like yum etc is depended on that.

When Ansible is install it picking the default python2 as INTERPRETER

Ansible --version
ansible 2.9.27 config file = /etc/ansible/ansible.cfg configured module search path = [u’/home/centos/.ansible/plugins/modules’, u’/usr/share/ansible/plugins/modules’] ansible python module location = /usr/lib/python2.7/site-packages/ansible executable location = /usr/bin/ansible python version = 2.7.5 (default, Jun 28 2022, 15:30:04) [GCC 4.8.5 20150623 (Red Hat 4.8.5-44)]

With the following link: I have set the Python INTERPRETER as Environment

IniSection [defaults]
Key interpreter_python
EnvironmentVariable ANSIBLE_PYTHON_INTERPRETER
Variablesname ansible_python_interpreter

But when I try executing kubernetes.core.helm: modules its throwing me an error:

TASK [adding] *************************************************************************************************************************************************************************************************
fatal: [ansible_host=“HOST IP”]: FAILED! => {“msg”: “Unable to import kubernetes.core.helm due to invalid syntax”}

here is my sample playbook

Python 2 is End of life and not supported by Ansible. Also, kubernetes.core collection is supported on Python3 (https://github.com/ansible-collections/kubernetes.core#python-support). I would recommend you upgrade to the latest Python version. After installing the latest Python 3 version use

---
- hosts: localhost
vars:
ansible_python_interpreter: /Path/to/bin/python3
tasks:
...

or


export ANSIBLE_PYTHON_INTERPRETER=/path/to/bin/python3

then run the playbook.

Apart from that --syntax-check would provide syntax errors for YAML files, not for the actual module that is being invoked.

Thanks Abhijeet for the answer

Using ansible in centos 7 in which python2 is set as default interpreter and some utilities is based on python2 like yum so can not change the python interpreter as default

Even try setting up python interpreter

  • within playbook
  • in Ansible.cfg
  • in inventory hosts file
  • as environment variable
    but no go anything else we you can suggest