diff --git a/.travis.yml b/.travis.yml index 3bf7603..e7226b5 100644 --- a/.travis.yml +++ b/.travis.yml @@ -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 @@ -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 diff --git a/defaults/main.yml b/defaults/main.yml index 6cc151d..c65982b 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -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 diff --git a/tasks/install.deb.yml b/tasks/install.deb.yml index d06d2f9..3725d65 100644 --- a/tasks/install.deb.yml +++ b/tasks/install.deb.yml @@ -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 }}" @@ -21,3 +31,4 @@ apt: name=python{{item}}-distutils state=present when: item >= 3 with_items: "{{ python_versions }}" + ignore_errors: true diff --git a/tasks/install.yum.yml b/tasks/install.yum.yml index 3232364..8acd427 100644 --- a/tasks/install.yum.yml +++ b/tasks/install.yum.yml @@ -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}}" diff --git a/tasks/python.yml b/tasks/python.yml index c334e72..12e688b 100644 --- a/tasks/python.yml +++ b/tasks/python.yml @@ -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 @@ -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" - diff --git a/test.yml b/test.yml index d04c627..7babfeb 100644 --- a/test.yml +++ b/test.yml @@ -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