From: Thanh Ha Date: Sat, 24 Feb 2018 19:43:32 +0000 (-0500) Subject: Migrate lf-ansible python-install role X-Git-Url: https://gerrit.linuxfoundation.org/infra/gitweb?a=commitdiff_plain;h=refs%2Fchanges%2F39%2F9039%2F1;p=ansible%2Froles%2Fpython-install.git Migrate lf-ansible python-install role Issue: RELENG-809 Change-Id: Ib29fb4580b00dd2c50e6a7b2168ebe8400965260 Signed-off-by: Thanh Ha --- diff --git a/README.md b/README.md index 2a5b9d1..0dc9697 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,10 @@ None. Role Variables -------------- -None. +pyenv_version: Version of pyenv to install. +python34_version: Version of Python 3.4 to install. +python35_version: Version of Python 3.5 to install. +python36_version: Version of Python 3.6 to install. Dependencies ------------ diff --git a/defaults/main.yml b/defaults/main.yml index 64fd893..b8d4d36 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -1,2 +1,5 @@ --- -# defaults file for python-install +pyenv_version: v1.2.1 +python34_version: 3.4.7 +python35_version: 3.5.4 +python36_version: 3.6.4 diff --git a/molecule/default/molecule.yml b/molecule/default/molecule.yml index daae1be..303396f 100644 --- a/molecule/default/molecule.yml +++ b/molecule/default/molecule.yml @@ -16,6 +16,17 @@ provisioner: name: ansible-lint scenario: name: default + test_sequence: + - lint + - destroy + - dependency + - syntax + - create + - prepare + - converge + - side_effect + - verify + - destroy verifier: name: testinfra lint: diff --git a/molecule/default/prepare.yml b/molecule/default/prepare.yml index 5358b3b..eff9510 100644 --- a/molecule/default/prepare.yml +++ b/molecule/default/prepare.yml @@ -1,5 +1,37 @@ --- - name: Prepare hosts: all - gather_facts: false - tasks: [] + gather_facts: true + tasks: + - name: Install Fedora EPEL repo + yum: + name: https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm + state: present + when: ansible_os_family == 'RedHat' + become: true + + - name: Install Git + package: name=git state=present + + - name: Install Python compile dependencies + yum: + name: + - bzip2-devel + - gcc + - make + - openssl-devel + state: present + when: ansible_os_family == 'RedHat' + become: true + + - name: Install Python compile dependencies + apt: + name: + - libbz2-dev + - gcc + - make + - libssl-dev + - wget + state: present + when: ansible_distribution == 'Ubuntu' + become: true diff --git a/tasks/main.yml b/tasks/main.yml index b9d9670..527e639 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -1,2 +1,34 @@ --- -# tasks file for python-install +- name: Include distro specific variables + include_vars: "{{item}}" + with_first_found: + - '{{ ansible_os_family }}.yml' + +- name: Install Python + package: + name: '{{ python_packages }}' + state: present + become: true + +- name: Install Python via pyenv + environment: + PYENV_ROOT: /opt/pyenv + PATH: '/opt/pyenv/bin:{{ansible_env.PATH}}' + PYTHON34_VERSION: '{{python34_version}}' + PYTHON35_VERSION: '{{python35_version}}' + PYTHON36_VERSION: '{{python36_version}}' + block: + - name: 'Install pyenv {{pyenv_version}}' + git: + repo: https://github.com/pyenv/pyenv.git + dest: /opt/pyenv + version: '{{pyenv_version}}' + - name: 'Install Python {{python34_version}}' + command: pyenv install -s "$PYTHON34_VERSION" + - name: 'Install Python {{python35_version}}' + command: pyenv install -s "$PYTHON35_VERSION" + - name: 'Install Python {{python36_version}}' + command: pyenv install -s "$PYTHON36_VERSION" + - name: Set pyenv global + command: pyenv global system "$PYTHON36_VERSION" "$PYTHON35_VERSION" "$PYTHON34_VERSION" + become: true diff --git a/vars/Debian.yml b/vars/Debian.yml new file mode 100644 index 0000000..c6174ce --- /dev/null +++ b/vars/Debian.yml @@ -0,0 +1,12 @@ +--- +python_packages_distro: + - python + - python-dev + - python-pip + - python-setuptools + - python-virtualenv + - python3 + - python3-dev + - python3-pip + - python3-setuptools + - python3-virtualenv diff --git a/vars/RedHat.yml b/vars/RedHat.yml new file mode 100644 index 0000000..da51ef1 --- /dev/null +++ b/vars/RedHat.yml @@ -0,0 +1,12 @@ +--- +python_packages_distro: + - python + - python-devel + - python-pip + - python-setuptools + - python-virtualenv + - python34 + - python34-devel + - python34-pip + - python34-setuptools + - python34-virtualenv diff --git a/vars/main.yml b/vars/main.yml index 0bc0efc..89a2340 100644 --- a/vars/main.yml +++ b/vars/main.yml @@ -1,2 +1,2 @@ --- -# vars file for python-install +python_packages: '{{ python_packages_distro }}'