【问题标题】:How to install ansible using ansible and pip如何使用 ansible 和 pip 安装 ansible
【发布时间】:2020-08-15 05:48:39
【问题描述】:

您好,我正在尝试在 ubuntu 服务器 Trusty64 中使用 vagrant 和 ansible 安装带有 pip 的 ansible。我使用角色安装python3,安装ansible的角色是:

---
# tasks file for roles/ansible
- name: install pip3
  apt: name=python3-pip state=present
  tags: ansible

- name: install librerias dev
  apt: name=libssl-dev state=present
  tags: ansible

- name: install librerias essential
  apt: name=build-essential state=present
  tags: ansible

- name: install librerias libdev
  apt: name=libffi-dev state=present
  tags: ansible

- name: install librerias pydev
  apt: name=python-dev state=present
  tags: ansible

- name: install librerias pydev
  apt: upgrade=yes
  tags: ansible

- name: install setuptools
  command: pip3 install setuptools
  tags: ansible

- name: upgrade setuptools
  command: pip3 install --upgrade setuptools
  tags: ansible

- name: install ansible
  command: pip3 install ansible
  tags: ansible

安装 python3 和 pip3 后安装失败,安装 ansible 并出现下一个错误回溯:

Python 3.5 or later is required",                                                                   
    "stderr_lines": [
        "Traceback (most recent call last):", 
        "  File \"/usr/bin/pip3\", line 5, in <module>", 
        "    from pkg_resources import load_entry_point", 
        "  File \"/usr/local/lib/python3.4/dist-packages/pkg_resources/__init__.py\", line 93, in <module>", 
        "    raise RuntimeError(\"Python 3.5 or later is required\")", 
        "RuntimeError: Python 3.5 or later is required"
    ], 
    "stdout": "", 
    "stdout_lines": []
}

我不明白为什么我也要解决这个问题,因为我已经使用这个角色安装了 python3:

---
# tasks file for roles/python3

- name: aniadir repositorio
  apt_repository: 
   repo: ppa:deadsnakes/ppa
   state: present

- name: actualizar cache
  apt: update_cache=yes

- name: instalar python3
  apt: name=python3.7 state=present

我已经使用 pip3 来安装 setuptools 并对其进行升级。我会很感激你的帮助。谢谢。

【问题讨论】:

    标签: python python-3.x ubuntu ansible


    【解决方案1】:

    根据this answer,需要添加:

    - name: Select python3.7 as default python3
      alternatives:
        name: python3
        path: /usr/bin/python3.7
    

    正如您在错误中看到的,Ansible 尝试使用 Python 3.4 安装 Ansible:

    /usr/local/lib/python3.4/dist-packages/pkg_resources/__init__.py

    Python 3.4 是您安装的默认 Python 3。安装 Python 3.7 只会安装 python3.7,但不会使其成为默认的 Python 3。为此,您必须在调用 python3 时明确告诉系统使用 python3.7,使用 alternatives system

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-24
      • 1970-01-01
      • 2021-12-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多