使用ansible在ubuntu中安装Python pip

使用ansible在ubuntu中安装Python pip,python,ubuntu,ansible,apt,Python,Ubuntu,Ansible,Apt,我试图使用ansible在ubuntu中安装Python pip,然后安装Python软件包,但在Python软件包安装任务中我遇到以下错误: failed: [X.X.X.X] (item=['psycopg2-binary']) => {"ansible_loop_var": "item", "changed": false, "item": ["psycopg2-binary"], &

我试图使用ansible在ubuntu中安装Python pip,然后安装Python软件包,但在Python软件包安装任务中我遇到以下错误:

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."}
我正在新创建的
AWS EC2 Ubuntu 14.04.1 LT
机器上从本地机器运行Ansible

创建_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
剧本中会有什么问题

编辑:

  • 添加ansible安装python pip任务的详细信息
  • 安装Python软件包

  • 这可能回答了你的问题,@senjoux实际上问题不在于psycopg2,即使我尝试安装任何其他python包。我也遇到同样的错误,当我在机器上签入pip时,它没有安装。@senjoux我可以通过bash shell安装上述软件包,但不能使用ansible。然后我怀疑ansible安装程序使用的python解释器,请提供所用解释器的详细信息好吗?@senjoux按照您的要求添加了详细信息。
    "ansible_facts": {"discovered_interpreter_python": "/usr/bin/python"}
    
    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])
    
    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."}