Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ansible - pip not found

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?

like image 235
Eduardo Avatar asked Aug 24 '18 04:08

Eduardo


People also ask

How do I fix pip not found?

A “pip: command not found” error occurs when you fail to properly install the package installer for Python (pip) needed to run Python on your computer. To fix it, you will either need to re-install Python and check the box to add Python to your PATH or install pip on your command line.

What is pip in Ansible?

Ansible pip module is used when you need to manage python libraries on the remote servers. There are two prerequisites if you need to use all the features in the pip module. The pip package should already be installed on the remote server.

Does Ansible need Python on target?

Most Ansible modules that execute under a POSIX environment require a Python interpreter on the target host. Unless configured otherwise, Ansible will attempt to discover a suitable Python interpreter on each target host the first time a Python module is executed for that host.


2 Answers

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
like image 113
iptizer Avatar answered Oct 02 '22 05:10

iptizer


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.

like image 28
sulabh chaturvedi Avatar answered Oct 02 '22 04:10

sulabh chaturvedi