Ansible-未找到点子

时间:2018-08-24 04:49:21

标签: ansible ansible-2.x

我收到此错误:

    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:

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吗?

5 个答案:

答案 0 :(得分:1)

似乎未安装pip,您可以使用以下任务进行安装:

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

答案 1 :(得分:1)

可能对点进行了哈希处理。意思是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。

答案 2 :(得分:0)

我刚刚在全新的CentOS 7上遇到了相同的问题。解决方法如下:首先安装setuptoolsyum,然后安装pipeasy_install,如下所示:< / p>

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

答案 3 :(得分:0)

对于基于 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 运行

答案 4 :(得分:0)

Ansible 未找到/安装 Pip

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

我在安装 pip 时遇到以下错误:

  • 通过 Ansible:

    <块引用>

    失败! => {"changed": false, "cmd": "/bin/easy_install --upgrade pip", "failed": true, "msg": "找不到 'pip' 的索引页(可能拼写错误?)

  • 直接在主机上:

    <块引用>

    正在寻找 pip 阅读https://pypi.python.org/simple/pip/ 找不到“pip”的索引页(可能拼写错误?) 扫描所有包的索引(这可能需要一段时间) 阅读https://pypi.python.org/simple/ 找不到 pip 的本地包或下载链接 错误:找不到合适的发行版 Requirement.parse('pip')

我尝试使用上面的 hash -r 答案: (注意:help hash... hash -r == 忘记所有记住的位置)

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

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

我通过另一篇帖子发现:'pip install' fails for every package ("Could not find a version that satisfies the requirement") 这是最终修复:

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 的 curl,这只是一个例子

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