zuul-jobs/roles/ensure-python/tasks/pyenv.yaml
Monty Taylor e71d0d2607 Add support for installing python with pyenv
In order to install particular python versions on distros that
don't otherwise have them, add an option for installing via
pyenv.

The packages to be installed to allow for Python to be built were
tested on the official Docker containers so they should provide
a fair amount of coverage from a minimal environment.

Co-Authored-By: Mohammed Naser <mnaser@vexxhost.com>
Change-Id: Ic3312458b499a4b743895fa5829bb25155f77654
2020-03-17 17:32:49 -04:00

38 lines
1.4 KiB
YAML

- name: Include OS-specific variables
include_vars: "{{ item }}"
with_first_found:
- "{{ ansible_distribution }}-{{ ansible_distribution_major_version }}.yaml"
- "{{ ansible_distribution }}.{{ ansible_architecture }}.yaml"
- "{{ ansible_distribution }}.yaml"
- "{{ ansible_os_family }}.yaml"
- name: Install python build depends
become: true
package:
name: "{{ python_build_depends }}"
- name: Clone pyenv repo
git:
repo: https://github.com/pyenv/pyenv.git
dest: "{{ ansible_user_dir }}/.pyenv"
version: master
# NOTE(mnaser): pyenv does not allow us to let it install Python from a specific
# series so we have to do some magic to find out what's the latest
# release from a series
- name: Determine Python version
shell: |
set -o pipefail
{{ ansible_user_dir }}/.pyenv/plugins/python-build/bin/python-build --definitions | grep ^{{ python_version }} | tail -1
args:
executable: /bin/bash
register: _python_version
# NOTE(mnaser): We install Python globally in the system, as that's somewhat
# similar to behaviour of installing a Python package. It also
# avoids us having to mess around $PATH.
- name: Install python
become: true
command: "{{ ansible_user_dir }}/.pyenv/plugins/python-build/bin/python-build {{ _python_version.stdout }} /usr/local"
environment:
CFLAGS: -O2