6

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?

Eduardo
  • 1,781
  • 3
  • 26
  • 61

6 Answers6

9

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
Eliezer Steinbock
  • 4,728
  • 5
  • 31
  • 43
iptizer
  • 1,088
  • 1
  • 10
  • 19
  • thanks for your answer, I will give it a try, I added an update to the question, shouldn't that task install pip? – Eduardo Aug 24 '18 at 05:58
  • I have added that task then run vagrant provision, but still same error – Eduardo Aug 24 '18 at 06:01
  • This may work better for you. The cache likely needs updating: ``` - name: install pip apt: name: python-pip update_cache: yes state: present ``` – Eliezer Steinbock Feb 15 '19 at 12:04
  • This didn't work for me! Had to follow --> https://stackoverflow.com/questions/45386971/importerror-no-module-named-pymysql-in-python-2-7 – Vineeth Sep 08 '19 at 10:13
2

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.

sulabh chaturvedi
  • 3,608
  • 3
  • 13
  • 25
0

I've just met the same problem on a brand new CentOS 7. Solved through installing setuptools with yum first and then pip with easy_install as below :

ansible default -b -m yum -a "name=python-setuptools state=present"
ansible default -b -m easy_install -a "name=pip state=present"
shell
  • 1
  • 2
0

For Debian Based systems (RUN THIS ON CLIENT SYSTEMS): first install package python-is-python3 then add alias for pip echo alias pip=pip3 >> ~/.bashrc

I know my solution would be dumb but It works.

# pip-fix.yml
- name: pip fix
  hosts: all
  become: true

  tasks:
    - name: install python-is-python3
      apt: name=python-is-python3 update_cache=yes state=present
    - name: creating alias
      shell: echo alias pip=pip3 >> ~/.bashrc

    - name: test and upgrade pip
      pip: name=pip state=latest
      tags:
        - packages

run using ansible-playbook pip-fix.yml

0

Ansible Not finding / Installing Pip

While not using the author's original details, i think this might help them or others.

I was getting the following error for installing pip:

  • via Ansible:

    FAILED! => {"changed": false, "cmd": "/bin/easy_install --upgrade pip", "failed": true, "msg": "Couldn't find index page for 'pip' (maybe misspelled?)

  • directly on the host:

    Searching for pip Reading https://pypi.python.org/simple/pip/ Couldn't find index page for 'pip' (maybe misspelled?) Scanning index of all packages (this may take a while) Reading https://pypi.python.org/simple/ No local packages or download links found for pip error: Could not find suitable distribution for Requirement.parse('pip')

I attempted to use the above hash -r answer: (NOTE: help hash... hash -r == forget all remembered locations)

- name: forget easy_install path
  shell: hash -r
  become: true

however this was not a solve for me.

I found via another post: 'pip install' fails for every package ("Could not find a version that satisfies the requirement") that this was the final fix:

curl https://bootstrap.pypa.io/get-pip.py | python

or

- name: manually install pip
  shell: curl https://bootstrap.pypa.io/pip/2.7/get-pip.py | python
  become: true

NOTE: i changed the pip version. Also, there is a better way to do a curl in ansible, this is simply an example

I then followed with the easy_install pip latest. to ensure it was up to date.

0

below fix worked for me

#ln -s /usr/local/bin/pip /usr/bin/pip