kubernetes.core.helm throwing Invalid Syntax

948 views
Skip to first unread message

DEEPANSHU DANG

unread,
Jul 20, 2022, 8:41:43 AM7/20/22
to Ansible Project
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
---
-  hosts: host
   gather_facts: true
   tasks:
     - name: Install Nginx Chart
       kubernetes.core.helm:
          name: nginx-server
          namespace: default
          chart_ref: bitnami/nginx

on the other hand when i check the syntax of ansible playbook following the command 

ansible-playbook <playbook.yaml> --syntax-check

response is ok 

Can you please assist me how can we fix this issue

Abhijeet Kasurde

unread,
Jul 21, 2022, 12:40:48 AM7/21/22
to ansible...@googlegroups.com
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.


--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/25b7335d-b609-454f-8451-d6f516a95364n%40googlegroups.com.


--
Thanks,
Abhijeet Kasurde

DEEPANSHU DANG

unread,
Oct 31, 2022, 5:16:36 AM10/31/22
to Ansible Project
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 
Reply all
Reply to author
Forward
0 new messages