3

I am trying to install Python-pip in ubuntu using ansible and then installing python package, But I am getting following error during Python package install task:

failed: [X.X.X.X] (item=['psycopg2-binary']) => {"ansible_loop_var": "item", "changed": false, "item": ["psycopg2-binary"], "msg": "Unable to find any of pip2, pip to use.  pip needs to be installed."}

I am running Ansible from my local machine on newly created AWS EC2 Ubuntu 14.04.1 LT machine.

create_python_package.yml

---
- name: setup python
  hosts: all
  gather_facts: false
  tasks:
  - name: Update apt repo and cache on all Debian/Ubuntu boxes
    apt: update_cache=yes force_apt_get=yes cache_valid_time=3600
    become: true
  - name: Upgrade all apt packages
    apt: upgrade=yes force_apt_get=yes
    become: true
  - name: Install Python pip
    apt: name={{ item }} update_cache=true state=present force_apt_get=yes
    with_items:
    - python-pip
    - python3-pip
    become: true
  - name: Install Python packages
    pip: name={{ item }}
    with_items:
    - psycopg2-binary
    become: true

What could be the issue in playbook?

EDIT:

"ansible_facts": {"discovered_interpreter_python": "/usr/bin/python"}
  1. Add verbose of ansible install python-pip task
changed: [X.X.X.X] => (item=['python-pip', 'python3-pip']) => {"ansible_loop_var": "item", "cache_update_time": 1622303070, "cache_updated": true, "changed": true, "item": ["python-pip", "python3-pip"], "stderr": "", "stderr_lines": 
[]) 
Reading package lists...                                                                                                                                                                                                                      
Building dependency tree...                                                                                                                                                                                                                   
Reading state information...                                                                                                                                                                                                                  
The following extra packages will be installed:                                                                                                                                                                                               
  binutils build-essential cpp cpp-4.8 dpkg-dev fakeroot g++ g++-4.8 gcc                                                                                                                                                                      
  gcc-4.8 gcc-4.8-base libalgorithm-diff-perl libalgorithm-diff-xs-perl                                                                                                                                                                       
  libalgorithm-merge-perl libasan0 libatomic1 libc-dev-bin libc6 libc6-dev                                                                                                                                                                    
  libcloog-isl4 libdpkg-perl libexpat1 libexpat1-dev libfakeroot                                                                                                                                                                              
  libfile-fcntllock-perl libgcc-4.8-dev libgmp10 libgomp1 libisl10 libitm1                                                                                                                                                                    
  libmpc3 libmpfr4 libpython3-dev libpython3.4 libpython3.4-dev                                                                                                                                                                               
  libpython3.4-minimal libpython3.4-stdlib libquadmath0 libstdc++-4.8-dev                                                                                                                                                                     
  libstdc++6 libtsan0 linux-libc-dev make manpages-dev python-chardet-whl                                                                                                                                                                     
  python-colorama python-colorama-whl python-distlib python-distlib-whl                                                                                                                                                                       
  python-html5lib python-html5lib-whl python-pip-whl python-pkg-resources                                                                                                                                                                     
  python-requests-whl python-setuptools python-setuptools-whl python-six-whl                                                                                                                                                                  
  python-urllib3-whl python-wheel python3-chardet python3-colorama python3-dev                                                                                                                                                                
  python3-distlib python3-html5lib python3-pkg-resources python3-requests                                                                                                                                                                     
  python3-setuptools python3-six python3-urllib3 python3-wheel python3.4                                                                                                                                                                      
  python3.4-dev python3.4-minimal                                                                                                                                                                                                             
Suggested packages:                                                                                                                                                                                                                           
  binutils-doc cpp-doc gcc-4.8-locales debian-keyring g++-multilib                                                                                                                                                                            
  g++-4.8-multilib gcc-4.8-doc libstdc++6-4.8-dbg gcc-multilib autoconf                                                                                                                                                                       
  automake1.9 libtool flex bison gdb gcc-doc gcc-4.8-multilib libgcc1-dbg                                                                                                                                                                     
  libgomp1-dbg libitm1-dbg libatomic1-dbg libasan0-dbg libtsan0-dbg                                                                                                                                                                           
  libquadmath0-dbg glibc-doc libstdc++-4.8-doc make-doc python-genshi                                                                                                                                                                         
  python-lxml python-distribute python-distribute-doc python3-genshi                                                                                                                                                                          
  python3-lxml python3.4-venv python3.4-doc binfmt-support                                                                                                                                                                                    
Recommended packages:                                                                                                                                                                                                                         
  python-dev-all                                                                                                                                                                                                                              
The following NEW packages will be installed:                                                                                                                                                                                                 
  binutils build-essential cpp cpp-4.8 dpkg-dev fakeroot g++ g++-4.8 gcc                                                                                                                                                                      
  gcc-4.8 libalgorithm-diff-perl libalgorithm-diff-xs-perl                                                                                                                                                                                    
  libalgorithm-merge-perl libasan0 libatomic1 libc-dev-bin libc6-dev                                                                                                                                                                          
  libcloog-isl4 libdpkg-perl libexpat1-dev libfakeroot libfile-fcntllock-perl                                                                                                                                                                 
  libgcc-4.8-dev libgmp10 libgomp1 libisl10 libitm1 libmpc3 libmpfr4                                                                                                                                                                          
  libpython3-dev libpython3.4 libpython3.4-dev libquadmath0 libstdc++-4.8-dev                                                                                                                                                                 
  libtsan0 linux-libc-dev make manpages-dev python-chardet-whl python-colorama                                                                                                                                                                
  python-colorama-whl python-distlib python-distlib-whl python-html5lib                                                                                                                                                                       
  python-html5lib-whl python-pip python-pip-whl python-requests-whl                                                                                                                                                                           
  python-setuptools python-setuptools-whl python-six-whl python-urllib3-whl                                                                                                                                                                   
  python-wheel python3-chardet python3-colorama python3-dev python3-distlib                                                                                                                                                                   
  python3-html5lib python3-pip python3-pkg-resources python3-requests                                                                                                                                                                         
  python3-setuptools python3-six python3-urllib3 python3-wheel python3.4-dev                                                                                                                                                                  
The following packages will be upgraded:                                                                               
  gcc-4.8-base libc6 libexpat1 libpython3.4-minimal libpython3.4-stdlib                                                
  libstdc++6 python-pkg-resources python3.4 python3.4-minimal                                                          
9 upgraded, 66 newly installed, 0 to remove and 223 not upgraded.                                                      
Inst gcc-4.8-base [4.8.2-19ubuntu1] (4.8.4-2ubuntu1~14.04.4 Ubuntu:14.04/trusty-updates [amd64]) [libstdc++6:amd64 ]   
Conf gcc-4.8-base (4.8.4-2ubuntu1~14.04.4 Ubuntu:14.04/trusty-updates [amd64]) [libstdc++6:amd64 ]                     
Inst libstdc++6 [4.8.2-19ubuntu1] (4.8.4-2ubuntu1~14.04.4 Ubuntu:14.04/trusty-updates [amd64])                         
Inst libc6 [2.19-0ubuntu6.3] (2.19-0ubuntu6.15 Ubuntu:14.04/trusty-updates [amd64])
.
.
.
.
Conf python3-html5lib (0.999-3~ubuntu1 Ubuntu:14.04/trusty-updates [all])
Conf python3-urllib3 (1.7.1-1ubuntu4.1 Ubuntu:14.04/trusty-updates [all])
Conf python3-requests (2.2.1-1ubuntu0.4 Ubuntu:14.04/trusty-updates [all])
Conf python3-setuptools (3.3-1ubuntu2 Ubuntu:14.04/trusty-updates [all])
Conf python3-pip (1.5.4-1ubuntu4 Ubuntu:14.04/trusty-updates [all])
Conf python3-wheel (0.24.0-1~ubuntu1.1 Ubuntu:14.04/trusty-updates [all])
  1. Install Python packages
failed: [X.X.X.X] (item=['psycopg2-binary']) => {"ansible_loop_var": "item", "changed": false, "item": ["psycopg2-binary"], "msg": "Unable to find any of pip2, pip to use.  pip needs to be installed."}                                
Vibhor Verma
  • 161
  • 1
  • 4
  • 13
  • This might answear your question, https://stackoverflow.com/questions/47318227/cannot-install-psycopg2-ubuntu/47318374 – senjoux May 28 '21 at 06:58
  • @senjoux actually the issue isn't the psycopg2, even I try install any other python package. I get same error, and when I check in machine if pip is installed, it isn't. – Vibhor Verma May 28 '21 at 17:43
  • @senjoux I am able to install the above packages through bash shell, but can't using ansible. – Vibhor Verma May 28 '21 at 19:32
  • Then I suspect the python interpreter used by your Ansible setup, would you please provide the verbose details of the used interpreter? – senjoux May 29 '21 at 12:05
  • @senjoux added details as you asked for. – Vibhor Verma May 29 '21 at 16:00
  • Thanks. Well it seems "pip" is not installed for the python interpreter version used by Ansible. Could you please check where "/usr/bin/python" is coming from:? ls -la /usr/bin/python – senjoux May 30 '21 at 09:39
  • It is coming from python2.7 ```lrwxrwxrwx 1 root root 9 Dec 21 2013 /usr/bin/python -> python2.7``` – Vibhor Verma May 30 '21 at 10:25
  • Hum I see, as a work-around you could try using the "command" module for task "Install Python packages" to install the "psycopg2-binary" package, e.g command: "/path/to/python -m pip install "psycopg2-binary" – senjoux May 30 '21 at 16:18

0 Answers0