Ansible - pip not found

痴心易碎 提交于 2020-01-23 08:34:27

问题


I am getting this error:

    TASK [pip] *********************************************************************
    failed: [default] (item=urllib3) => 
{"changed": false, "item": "urllib3", 
"msg": "Unable to find any of pip2, pip to use.  pip needs to be installed."}

Upon a suggestion I run following command:

ansible default -a "which pip"

I get an error:

default | FAILED | rc=1 >>
non-zero return code

So I guess that means no pip installed. I tried installing pip using:

ansible default -a "easy_install pip"

I get the following error:

default | FAILED | rc=2 >>
[Errno 2] No such file or directory

Any ideas?

UPDATE In play_local.yaml, I have the following task:

- name: Prepare system
  hosts: default
  become: yes
  gather_facts: false
  pre_tasks:
    - raw: sudo apt-get -y install python python-setuptools python-pip build-essential libssl-dev libffi-dev python-dev easyinstall pip
    - file: path=/etc/sudoers.d/ssh-auth-sock state=touch mode=0440
      #- lineinfile: line='Defaults env_keep += "SSH_AUTH_SOCK"' path=/etc/sudoers.d/ssh-auth-sock
    - replace:
        path: /etc/apt/sources.list
        regexp: 'br.'
        replace: ''

Shouldn't this task install pip?


回答1:


May be pip is hashed. Meaning pip is installed at path x (may be /usr/local/bin/pip), however, cached at path y (may be /usr/bin/pip). You can confirm that from - ansible default -m shell -a ‘type pip’. To resolve this you’ll need to run - ansible default -m shell -a ‘hash -r’.

BTW, you can also use command module instead of shell.




回答2:


Seems like pip is not installed, you can use the following task to install it:

- name: Install pip
  apt:
    name: python-pip
    update_cache: yes
    state: present


来源:https://stackoverflow.com/questions/51997637/ansible-pip-not-found

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!