Migrate lf-ansible python-install role 39/9039/1
authorThanh Ha <thanh.ha@linuxfoundation.org>
Sat, 24 Feb 2018 19:43:32 +0000 (14:43 -0500)
committerThanh Ha <thanh.ha@linuxfoundation.org>
Sat, 24 Feb 2018 19:43:54 +0000 (14:43 -0500)
Issue: RELENG-809
Change-Id: Ib29fb4580b00dd2c50e6a7b2168ebe8400965260
Signed-off-by: Thanh Ha <thanh.ha@linuxfoundation.org>
README.md
defaults/main.yml
molecule/default/molecule.yml
molecule/default/prepare.yml
tasks/main.yml
vars/Debian.yml [new file with mode: 0644]
vars/RedHat.yml [new file with mode: 0644]
vars/main.yml

index 2a5b9d1..0dc9697 100644 (file)
--- 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
 ------------
index 64fd893..b8d4d36 100644 (file)
@@ -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
index daae1be..303396f 100644 (file)
@@ -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:
index 5358b3b..eff9510 100644 (file)
@@ -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
index b9d9670..527e639 100644 (file)
@@ -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 (file)
index 0000000..c6174ce
--- /dev/null
@@ -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 (file)
index 0000000..da51ef1
--- /dev/null
@@ -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
index 0bc0efc..89a2340 100644 (file)
@@ -1,2 +1,2 @@
 ---
-# vars file for python-install
+python_packages: '{{ python_packages_distro }}'