Ansible - 找不到点

Ansible - pip not found

我收到这个错误:

    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."}

根据建议我 运行 以下命令:

ansible default -a "which pip"

我得到一个错误:

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

所以我猜这意味着没有安装 pip。我尝试使用以下方式安装 pip:

ansible default -a "easy_install pip"

我收到以下错误:

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

有什么想法吗?

更新 在play_local.yaml,我有以下任务:

- 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: ''

这个任务不应该安装pip吗?

好像没有安装pip,可以使用以下任务安装:

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

可能是 pip 被散列了。这意味着 pip 安装在路径 x(可能是 /usr/local/bin/pip),但是缓存在路径 y(可能是 /usr/bin/pip))。您可以从 - ansible default -m shell -a ‘type pip’ 确认。要解决这个问题,您将需要 运行 - ansible default -m shell -a ‘hash -r’.

顺便说一句,你也可以使用命令模块代替shell。

我刚刚在全新的 CentOS 7 上遇到了同样的问题。通过先安装 setuptoolsyum 然后安装 pipeasy_install 解决了问题,如下所示:

ansible default -b -m yum -a "name=python-setuptools state=present"
ansible default -b -m easy_install -a "name=pip state=present"

对于基于 Debian 的系统(运行 这在客户端系统上): 首先安装包 python-is-python3 然后为 pip 添加别名 echo alias pip=pip3 >> ~/.bashrc

我知道我的解决方案很愚蠢,但它有效。

# 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

运行 使用 ansible-playbook pip-fix.yml

Ansible 未找到/安装 Pip

虽然没有使用作者的原始详细信息,但我认为这可能对他们或其他人有所帮助。

安装 pip 时出现以下错误:

  • 通过 Ansible:

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

  • 直接在主机上:

    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')

我尝试使用上面的 hash -r 答案: (注意:help hash... hash -r == forget all remembered locations)

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

然而这对我来说不是解决方案。

我通过另一个 post 发现: 这是最终修复:

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

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

注意:我更改了 pip 版本。此外,还有一种更好的方法可以在 ansible 中进行卷曲,这只是一个示例

然后我关注了 easy_install pip 最新的。以确保它是最新的。

下面的修复对我有用

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