Skip to content
42 changes: 30 additions & 12 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,27 +1,45 @@
---
language: python
python:
- "2.7"
# - "3.4"
# - "2.7"
- "3.6"
env:
- ANSIBLE_VERSION=2.3.1.0
cache: bundler
#sudo: false
- ANSIBLE_VERSION=latest

services:
- docker

cache:
bundler:
directories:
- $HOME/.cache/pip

# sudo: false
sudo: required
dist: trusty

virtualenv:
system_site_packages: false

before_install:
- sudo apt-get update -qq
- sudo apt-get install -qq python-apt python-pycurl
install:
# Install Ansible.
- sudo pip install ansible==$ANSIBLE_VERSION
- if [ "$ANSIBLE_VERSION" = "latest" ]; then pip install ansible; else pip install ansible==$ANSIBLE_VERSION; fi
- if [ "$ANSIBLE_VERSION" = "latest" ]; then pip install ansible-lint; fi

- pip install molecule
script:
# Prepare tests
- echo localhost > inventory

# Check syntax
- ansible-playbook --syntax-check -i inventory test.yml


# Molecule test
# - molecule test

# First run
- ansible-playbook -i inventory test.yml --connection=local --sudo

Expand All @@ -34,17 +52,17 @@ script:

- command -v python || exit 1
- command -v pip || exit 1
- command -v python2.7 || exit 1
- command -v pip2.7 || exit 1
- command -v python3.6 || exit 1
- command -v pip3.6 || exit 1
- command -v virtualenv || exit 1

# Test with python3.4
- ansible-playbook -i inventory test.yml --connection=local --sudo -e "python_version=3.4"
#- ansible-playbook -i inventory test.yml --connection=local --sudo -e "python_versions=[3.4]"

#- command -v python3.4 || exit 1
#- command -v pip3.4 || exit 1

python_install: [virtualenv]
python_versions: [2.7]
python_versions: [3.6]
python_bin: /usr/bin/python
python_pkg_bin: /home/travis/virtualenv/python2.7.13/bin
#python_pkg_bin: /home/travis/virtualenv/python2.7.14/bin
1 change: 1 addition & 0 deletions defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@ python_bin: /usr/bin/python
python_pkg_bin: /usr/local/bin
python_yum_disablerepo: no
python_yum_enablerepo: no
python_pip_installed_enabled: yes # Pip install is enabled
15 changes: 13 additions & 2 deletions tasks/install.deb.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,21 @@

- name: Install python-pycurl
apt: name=python-pycurl

when: item < 3
with_items: "{{ python_versions }}"
ignore_errors: true

- name: Install python3-pycurl
apt: name=python3-pycurl
when: item >= 3
with_items: "{{ python_versions }}"

- name: Add python apt repository
apt_repository: repo={{python_ppa}} update_cache=yes
when: python_ppa != False and python_ppa != ""

become: true
ignore_errors: true

- name: Install python
apt: name=python{{item}} state=present
with_items: "{{ python_versions }}"
Expand All @@ -21,3 +31,4 @@
apt: name=python{{item}}-distutils state=present
when: item >= 3
with_items: "{{ python_versions }}"
ignore_errors: true
15 changes: 11 additions & 4 deletions tasks/install.yum.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
---

#regex_replace fail when there is an int
#- debug: msg="python_versions {{ item|map('regex_replace', '.','')|list }}"
# with_items: "{{python_versions}}"

- debug: msg="python_versions {{ item|replace('.','') }}"
with_items: "{{python_versions}}"

- name: Install python
yum: name=python{{item | regex_replace('.')}} state=present enablerepo={{python_yum_enablerepo or None}} disablerepo={{python_yum_disablerepo or None}}
with_items: "{{ python_versions }}"
yum: name=python{{item|replace('.','')}} state=present enablerepo={{python_yum_enablerepo or None}} disablerepo={{python_yum_disablerepo or None}}
with_items: "{{python_versions}}"

- name: Install python-dev
yum: name=python{{item | regex_replace('.')}}-devel state=present enablerepo={{python_yum_enablerepo or None}} disablerepo={{python_yum_disablerepo or None}}
with_items: "{{ python_versions }}"
yum: name=python{{item|replace('.','')}}-devel state=present enablerepo={{python_yum_enablerepo or None}} disablerepo={{python_yum_disablerepo or None}}
with_items: "{{python_versions}}"
23 changes: 16 additions & 7 deletions tasks/python.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,14 @@

- name: Install pip - pt. 1
copy: src=get-pip.py dest=/usr/share/python/get-pip.py
when: python_pip_installed_enabled

- name: Install pip - pt. 2
shell: "{{python_bin}}{{item}} /usr/share/python/get-pip.py creates={{python_pkg_bin}}/pip{{item}}"
shell: "{{python_bin}}{{item|replace('u','')}} /usr/share/python/get-pip.py creates={{python_pkg_bin}}/pip{{item|replace('u','')}}"
with_items: "{{ python_versions }}"
register: python_pip_installed
changed_when: false
when: python_pip_installed_enabled
become: yes

- name: Update tools
Expand All @@ -28,25 +30,32 @@
- name: Install global python packages
pip: name="{{python_install|join(' ')}}" executable={{python_pkg_bin}}/pip{{item}}
when: python_install
with_items: "{{ python_versions }}"
with_items: "{{python_versions}}"

- name: Install virtualenv
pip: name="virtualenv" executable={{python_pkg_bin}}/pip{{item}}
pip: name="virtualenv" executable={{python_pkg_bin}}/pip{{item|replace('u','')}}
when: not( (python_virtualenvs is undefined) or (python_virtualenvs is none) or (python_virtualenvs | trim == '') )
with_items: "{{ python_versions }}"
with_items: "{{python_versions}}"

- name: Setup virtualenvs
shell: virtualenv {{item.path}} --python={{item.python|default('python')}}
args:
creates: "{{item.path}}"
with_items: "{{ python_virtualenvs }}"
with_items: "{{python_virtualenvs}}"
tags:
- venv
environment:
PATH: "{{ansible_env.PATH}}:{{ansible_user_dir}}/.local/bin"
when: "python_virtualenv_user is not defined"

- name: Setup virtualenvs for specific user
shell: virtualenv {{item.path}} --python={{item.python|default('python')}}
args:
creates: "{{item.path}}"
with_items: "{{ python_virtualenvs }}"
with_items: "{{python_virtualenvs}}"
tags:
- venv
environment:
PATH: "{{ansible_env.PATH}}:{{ansible_user_dir}}/.local/bin"
become_user: "{{item.user|default(python_virtualenv_user)}}"
when: "python_virtualenv_user is defined"

6 changes: 5 additions & 1 deletion test.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
- hosts: all
- hosts: localhost
tasks:
- import_tasks: tasks/main.yml
vars_files:
- defaults/main.yml
- .travis.yml
vars:
python_ppa: ""
python_versions: [3.6, 3.8]
python_pip_installed_enabled: false