-
Notifications
You must be signed in to change notification settings - Fork 23.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
k8s module throwing 'This module requires the OpenShift Python client. Try pip install openshift
'
#50529
Comments
Files identified in the description: If these files are inaccurate, please update the |
Created a test python script: try:
import kubernetes
import openshift
from openshift.dynamic import DynamicClient
from openshift.dynamic.exceptions import ResourceNotFoundError, ResourceNotUniqueError
print "Found it"
except ImportError:
print "Didnt find it" Ran it:
So... looks like there's some weird error with Is there any way to bubble up the actual exception instead of just blindly setting |
So in my case, it was an annoying Requests-related exception (actually just a
(For context, see psf/requests#4673) Now everything is working happily. But I want to leave this open in case it's deemed a bug that the |
@geerlingguy thanks a ton for the investigation, that's definitely a weird one. I'll try and get that error properly bubbled up. |
Same here: Ansible 2.7.5 I am simply using the k8s module and get the above error. |
+1 |
Tested in 2.6.11 version also ... same error and same issue.
Error Message :
|
If you have - hosts: master
connection: local
vars:
ansible_python_interpreter: '{{ ansible_playbook_python }}'
tasks:
- name: Create a kubernetes namespace
k8s_raw:
name: testing
api_version: v1
kind: Namespace
state: present Does that fix your issue @kylix3511 or @ClaudioDeFacci? Edit: Including Will Thames' excellent blog post on this subject: https://willthames.github.io/2018/07/01/connection-local-vs-delegate_to-localhost.html |
Thanks @fabianvf.
vars:
ansible_python_interpreter: '{{ ansible_playbook_python }}'
Thats helpful and worked.
Now my goal is to use ansible AWX to use the same operations. Any idea to how to do that ? Have you done that before ?
… On Jan 8, 2019, at 12:27 PM, Fabian von Feilitzsch ***@***.***> wrote:
If you have openshift installed in a virtual environment, you may need to specify the proper python intepreter for Ansible to use (by default it will use your system python). You can do that by setting the ansible_python_interpreter variable to ansible_playbook_python. Your new play would look like:
- hosts: master
connection: local
vars:
ansible_python_interpreter: '{{ ansible_playbook_python }}'
tasks:
- name: Create a kubernetes namespace
k8s_raw:
name: testing
api_version: v1
kind: Namespace
state: present
Does that fix your issue @kylix3511 <https://github.com/kylix3511> or @ClaudioDeFacci <https://github.com/ClaudioDeFacci>?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub <#50529 (comment)>, or mute the thread <https://github.com/notifications/unsubscribe-auth/Ak2Op5Ip7fVoHH24brKpkwZCGn4wwuxnks5vBP87gaJpZM4ZpCBb>.
|
No, I haven't used AWX very extensively so I can't really be of much help there. I'd recommend asking in IRC. |
Just hit this again today on my other Mac, after I ran a On this computer, the problem was that the system Python ( So I ran:
And now I'm back in business... after also updating |
@kylix3511 we got this working in AWX by setting up a custom virtual environment, like here so you have the proper pip dependencies installed, and by setting the "ansible_python_interpreter" with an extra var in the job template in AWX. then, locally just setting the "ansible_python_interpreter as global group_var to "ansible_playbook_python" as @fabianvf had said. it seems like it might be a bug within the AWX custom environment feature. like the error checking for the playbook isn't using the custom venv or something. |
@geerlingguy - rather than updating system python, it's better to set Also, for anyone reporting these issues, it's hugely helpful to put a For example:
would be helpful here |
Thanks Will. python_requriments_facts is very useful tip. Thanks so much.
I try to use python_requriments_facts, it is not working as expected. Please help if you got some time.
kylix3511 (e) venv280 ~ ansible helloWorldApp cat deployHelloWorld.yaml
…---
- hosts: localhost
connection: local
vars:
ansible_python_interpreter: '{{ ansible_playbook_python }}'
- python_requirements_facts:
dependencies:
- openshift
- requests
tasks:
- name: Deploying the simple HelloWorld App in Kylix3511 Namespace
k8s:
state: present
definition:
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
annotations:
deployment.kubernetes.io/revision: "1"
labels:
run: myhelloworld10
name: myhelloworld10
namespace: “kylix3511"
spec:
replicas: 5
selector:
matchLabels:
run: myhelloworld10
template:
metadata:
labels:
run: myhelloworld10
spec:
containers:
- image: hub.docker.com/images/myhelloworldapp10:v5
imagePullPolicy: Always
name: myhelloworld10
On Feb 2, 2019, at 4:10 PM, Will Thames ***@***.***> wrote:
@geerlingguy <https://github.com/geerlingguy> - rather than updating system python, it's better to set ansible_python_interpreter to ansible_playbook_python as @fabianvf <https://github.com/fabianvf> suggests.
Also, for anyone reporting these issues, it's hugely helpful to put a python_requirements_facts task in your playbook so that you can see what is actually being run.
For example:
- python_requirements_facts:
dependencies:
- openshift
- requests
would be helpful here
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub <#50529 (comment)>, or mute the thread <https://github.com/notifications/unsubscribe-auth/Ak2Op2cUxqRbLmZghYlMDWXR5AlBQqDWks5vJikCgaJpZM4ZpCBb>.
|
looks like you have a typo there? - here's the reference for proper syntax. otherwise, are you getting output at all? or just an error? should show what requirements are and are not being met. |
Thanks @benwsapp. Yes. I did try that ... still same error.
|
@kylix3511 - the
|
Thanks @willthames It works as expected.
|
Did any body tried and deployed a simple HelloWorld application in Kubernetes via ansible ?? I'm trying to do that last few days ... |
@Asgoret glad you solved it, just fyi I believe the |
@fabianvf I test simple construction (only |
@Asgoret newer versions of the k8s module have slightly improved error messages showing python path etc. |
@kylix3511 wrote:
Same here, RedHat 7.6, ansible 2.7.7, Python 2.7.5, except Tower 3.3.4 and using a custom Ansible Environment that has been setup just for this task (See playbook below) - the Tower documentation and RH support recommend this. When we specify the custom environment via Tower/AWX we still get the error. The output from
The Tower virtual environment is setup on all Tower nodes using this playbook:
|
+1 |
My problem was resolved with
Havent worked out whats happening behind scenes :( |
@mukeshmurali was your fix for the Tower/AWX installation, or another command line environment fix? I tried your |
Two questions for those more knowledgeable in "pip" and Python modules: P.S. I'm still learning about Python and 'pip' so excuse me in advance if those questions are bad. |
Is ansible/awx#2462 (comment) helpful here? |
So for those who have struggled with this, my Ansible Tower clusters now have a working solution too. Basically we:
Pip package installation used the This leads me to believe that there's some "leakage" of the virtual environments within the Tower system that are not properly sandboxing the I hope this helps others, if only as a band-aid until the real solution is found. Below is the Ansible playbook I wrote to set this up on my Tower servers:
Edit 1 - Update playbook to show the "pip update setuptools" step. |
So, the fix here was to add these Python modules to the underlying core OS package "World" and not just to the Tower virtual environments. Is this a problem in the way Python and/or the "k8s" module checks for pre-requisites, or is it a AWX pre-requisite checking failure? |
As far as I know the |
I was having this issue on a Mac using the homebrew version. My fix was to remove the homebrew version of Ansible and install using pip. |
I'm suspecting that too, but my support engineer at RedHat says that since the "k8s" module is not part of the core that RedHat provides, his options are limited. I guess I'll take my work-around for now and hope that future modules the teams need don't require a conflicting module. If anyone has any pointers on where to start debugging the version checking within the virtualenv I'm all ears. |
There does seem to be a parallel AWX issue for this (ansible/awx#2462) - this problem seems to be more about AWX/Tower than the |
Thanks @willthames that does seem quite familiar. |
Is there even a working workaround for this issue? I'm not (knowingly, I've never heard of it) using AWX Tower, I'm just running ansible on a Mac against a Linux remote. Initially I was running brew ansible in a pyenv virtual environment with openshift installed, but following above comments I've tried installing both ansible and openshift to system python environment, and that ansible still gives this error. The error doesn't make it clear if openshift should be installed on local or remote, so before I found this issue I was adding tasks to install pip and openshift on the remote, which hasn't helped either. |
@OJFord - usually it's almost always that if you're using Openshift should be installed on whatever host ansible is running on. As discussed earlier in the thread, you can use |
@willthames Thanks - so I still can't make it work though. [local]
localhost ansible_python_interpreter="{{ ansible_playbook_python }}"
{"valid": {"openshift": {"desired": null, "installed": "0.8.8"}, "requests": {"desired": null, "installed": "2.21.0"}, ...} and shows the
{"changed": false, "msg": "This module requires the OpenShift Python client. Try `pip install openshift`"} |
@OJFord can you run the playbook with |
@willthames That actually shows it's using It runs:
and gives the same error about installing openshift.
confirms it is installed. |
Ok, if you're seeing Are you trying to run ansible on a target host to make kubernetes api calls? Do you have a reason to do that (either way is fine, but I'm troubleshooting a problem without all of the information) You're only giving me minimal snippets of information, this would be much better investigated as a new separate issue, with a proper minimal reproducible test case (https://stackoverflow.com/help/mcve) - creating such a thing is often a good path to isolating the issue and finding the cause of the issue yourself. |
I'm going to close this issue now. If people are having an issue that appears similar to this one, please open a new issue fully describing your problem. |
SUMMARY
So, I've already read through all of the following earlier issues:
And I've been debugging this issue for my Pi Dramble project (within a Vagrant environment) locally for a couple days; see Switch to geerlingguy.k8s_manifests role. I think I'm close to a solution, but because this road has been windy, and ridiculously weird, I thought I'd post an issue here, and at least document how I solved it (if I can get it solved, ha!) for the benefit of future searchers... and myself, when I inevitably run into the problem again!
ISSUE TYPE
COMPONENT NAME
k8s
ANSIBLE VERSION
CONFIGURATION
OS / ENVIRONMENT
macOS Mojave (10.14)
STEPS TO REPRODUCE
Playbook:
Inventory:
EXPECTED RESULTS
Kubernetes manifests will be applied to the K8s cluster.
ACTUAL RESULTS
First thing I tried was verifying
openshift
was installed in the python being used:(I also tried everything with
openshift==0.8.1
just to rule out version issues.).That's odd.
So then I added a debug statement to the playbook:
And the output:
So... what gives?
The text was updated successfully, but these errors were encountered: