如何使用ansible和pip安装ansible

2024-06-16 11:25:28 发布

您现在位置:Python中文网/ 问答频道 /正文

您好,我正在尝试在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。谢谢你的帮助。谢谢


Tags: installnamedev角色pip3tagsaptansible
1条回答
网友
1楼 · 发布于 2024-06-16 11:25:28

根据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

Python3.4是您安装的默认Python3。安装Python3.7只会安装python3.7,但不会使其成为默认的Python3。为此,在调用python3时,必须使用alternatives system显式地告诉系统使用python3.7

相关问题 更多 >