jhaos
jhaos

Reputation: 37

How to install ansible using ansible and pip

Hi I'm trying to install ansible with pip using vagrant and ansible in a ubuntu server Trusty64. I used roles to install python3 and in the role to install ansible is:

---
# 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

After python3 is installed and pip3 the installation fails installing ansible with the next error traceback:

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": []
}

And I cannot see why should I too to solve this because I already have installed python3 using this role:

---
# 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

and I already used pip3 to install setuptools and to upgrade it. I would appreciate your help. Thanks.

Upvotes: 0

Views: 2790

Answers (1)

duthils
duthils

Reputation: 1391

According to this answer, you need to add:

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

As you can see in the error, Ansible tries to install Ansible with Python 3.4:

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

Python 3.4 is the default Python 3 for your installation. Installing Python 3.7 only installs python3.7 but does not make it the default Python 3. To do this, you must explicitly tell the system to use python3.7 when calling python3, using the alternatives system.

Upvotes: 1

Related Questions