From f6a0f44da5ab84d7fe8cff6035fc24addca0defd Mon Sep 17 00:00:00 2001 From: "Andrieu, Alban" Date: Wed, 3 Oct 2018 18:47:56 +0200 Subject: [PATCH 01/12] Fix when using int or string in python_versions: ["3.6"] --- tasks/install.yum.yml | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/tasks/install.yum.yml b/tasks/install.yum.yml index 3232364..1e675ac 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('.','')|list }}" + 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}}" From 777e05a993b80d2aae0556f530cefcf90ff7a553 Mon Sep 17 00:00:00 2001 From: "Andrieu, Alban" Date: Wed, 3 Oct 2018 18:58:16 +0200 Subject: [PATCH 02/12] Fix travis --- .travis.yml | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/.travis.yml b/.travis.yml index 3bf7603..b251b10 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,9 +4,9 @@ python: - "2.7" # - "3.4" env: - - ANSIBLE_VERSION=2.3.1.0 + - ANSIBLE_VERSION=latest cache: bundler -#sudo: false +# sudo: false sudo: required dist: trusty before_install: @@ -14,7 +14,8 @@ before_install: - 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 script: # Prepare tests - echo localhost > inventory @@ -39,7 +40,7 @@ script: - 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 From 3e038037ceed56a40b8735b597978335513a614d Mon Sep 17 00:00:00 2001 From: "Andrieu, Alban" Date: Wed, 3 Oct 2018 19:04:30 +0200 Subject: [PATCH 03/12] Fix travis. No python3.5-distutils package but python3-distutils --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index b251b10..0f24e8c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -40,7 +40,7 @@ script: - command -v virtualenv || exit 1 # Test with python3.4 - - ansible-playbook -i inventory test.yml --connection=local --sudo -e "python_versions=[3.4]" + - ansible-playbook -i inventory test.yml --connection=local --sudo -e "python_versions=[3]" #- command -v python3.4 || exit 1 #- command -v pip3.4 || exit 1 From 2f0153b8d05156cf8fc965fa7ba7b533d65575ec Mon Sep 17 00:00:00 2001 From: "Andrieu, Alban" Date: Wed, 3 Oct 2018 19:16:53 +0200 Subject: [PATCH 04/12] Fix travis. No python3.5-distutils package but python3.7-distutils --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 0f24e8c..051a1d6 100644 --- a/.travis.yml +++ b/.travis.yml @@ -40,7 +40,7 @@ script: - command -v virtualenv || exit 1 # Test with python3.4 - - ansible-playbook -i inventory test.yml --connection=local --sudo -e "python_versions=[3]" + - ansible-playbook -i inventory test.yml --connection=local --sudo -e "python_versions=[3.7]" #- command -v python3.4 || exit 1 #- command -v pip3.4 || exit 1 From 920c5e8aefef31dbbd617e40b3402a9524a6b734 Mon Sep 17 00:00:00 2001 From: "Andrieu, Alban" Date: Wed, 3 Oct 2018 19:45:43 +0200 Subject: [PATCH 05/12] Fix for .travis --- .travis.yml | 2 +- tasks/install.deb.yml | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 051a1d6..b251b10 100644 --- a/.travis.yml +++ b/.travis.yml @@ -40,7 +40,7 @@ script: - command -v virtualenv || exit 1 # Test with python3.4 - - ansible-playbook -i inventory test.yml --connection=local --sudo -e "python_versions=[3.7]" + - 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 diff --git a/tasks/install.deb.yml b/tasks/install.deb.yml index d06d2f9..df85883 100644 --- a/tasks/install.deb.yml +++ b/tasks/install.deb.yml @@ -21,3 +21,4 @@ apt: name=python{{item}}-distutils state=present when: item >= 3 with_items: "{{ python_versions }}" + ignore_errors: true From b1eaf1bc95d97ebed87e48f6a8e9511923dec671 Mon Sep 17 00:00:00 2001 From: "Andrieu, Alban" Date: Wed, 3 Oct 2018 19:56:24 +0200 Subject: [PATCH 06/12] Fix for .travis --- .travis.yml | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index b251b10..ce5c162 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,10 +5,22 @@ python: # - "3.4" env: - ANSIBLE_VERSION=latest -cache: bundler + +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 @@ -16,13 +28,18 @@ install: # Install Ansible. - 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 @@ -48,4 +65,4 @@ script: python_install: [virtualenv] python_versions: [2.7] 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 From 472b60ca68c3b350f63d2855c02b4373e16fef4f Mon Sep 17 00:00:00 2001 From: "Andrieu, Alban" Date: Wed, 3 Oct 2018 20:11:32 +0200 Subject: [PATCH 07/12] Fix for .travis --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index ce5c162..e16d16a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -57,7 +57,7 @@ script: - command -v virtualenv || exit 1 # Test with python3.4 - - ansible-playbook -i inventory test.yml --connection=local --sudo -e "python_versions=[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 From 48fdce42aff03f81c2b73a6b925fd357797e3ff4 Mon Sep 17 00:00:00 2001 From: "Andrieu, Alban" Date: Wed, 3 Oct 2018 21:32:25 +0200 Subject: [PATCH 08/12] Allow by default --system-site-package --- tasks/python.yml | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/tasks/python.yml b/tasks/python.yml index c334e72..255d160 100644 --- a/tasks/python.yml +++ b/tasks/python.yml @@ -36,17 +36,26 @@ with_items: "{{ python_versions }}" - name: Setup virtualenvs - shell: virtualenv {{item.path}} --python={{item.python|default('python')}} - args: - creates: "{{item.path}}" + pip: + virtualenv: {{item.path}} + virtualenv_python: {{item.python|default('python')}} + virtualenv_site_packages: false 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}}" + pip: + virtualenv: {{item.path}} + virtualenv_python: {{item.python|default('python')}} + virtualenv_site_packages: false 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" - From 54962ffc0c17ec376a3cc83248973f5d0316dcb9 Mon Sep 17 00:00:00 2001 From: "Andrieu, Alban" Date: Tue, 9 Oct 2018 12:25:34 +0200 Subject: [PATCH 09/12] Allow by default --system-site-package --- tasks/python.yml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tasks/python.yml b/tasks/python.yml index 255d160..37e62e0 100644 --- a/tasks/python.yml +++ b/tasks/python.yml @@ -37,8 +37,8 @@ - name: Setup virtualenvs pip: - virtualenv: {{item.path}} - virtualenv_python: {{item.python|default('python')}} + virtualenv: "{{ item.path }}" + virtualenv_python: "{{ item.python|default('python') }}" virtualenv_site_packages: false with_items: "{{ python_virtualenvs }}" tags: @@ -49,13 +49,13 @@ - name: Setup virtualenvs for specific user pip: - virtualenv: {{item.path}} - virtualenv_python: {{item.python|default('python')}} + virtualenv: "{{ item.path }}" + virtualenv_python: "{{ item.python|default('python') }}" virtualenv_site_packages: false with_items: "{{ python_virtualenvs }}" tags: - venv environment: PATH: "{{ ansible_env.PATH }}:{{ ansible_user_dir }}/.local/bin" - become_user: "{{item.user|default(python_virtualenv_user)}}" + become_user: "{{ item.user|default(python_virtualenv_user) }}" when: "python_virtualenv_user is defined" From d34c0e4dfe5e59b447807e160ed5024916eb9ac1 Mon Sep 17 00:00:00 2001 From: "Andrieu, Alban" Date: Tue, 13 Nov 2018 16:44:10 +0100 Subject: [PATCH 10/12] Allow python_versions: [3.5u] for centos (by removing the u) --- tasks/install.yum.yml | 12 ++++++------ tasks/python.yml | 32 +++++++++++++++----------------- 2 files changed, 21 insertions(+), 23 deletions(-) diff --git a/tasks/install.yum.yml b/tasks/install.yum.yml index 1e675ac..8acd427 100644 --- a/tasks/install.yum.yml +++ b/tasks/install.yum.yml @@ -3,14 +3,14 @@ #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('.','')|list }}" - with_items: "{{python_versions}}" - + +- debug: msg="python_versions {{ item|replace('.','') }}" + with_items: "{{python_versions}}" + - name: Install python - yum: name=python{{ item|replace('.','') }} state=present enablerepo={{python_yum_enablerepo or None}} disablerepo={{python_yum_disablerepo or None}} + 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|replace('.','') }}-devel state=present enablerepo={{python_yum_enablerepo or None}} disablerepo={{python_yum_disablerepo or None}} + 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 37e62e0..cf3fb8d 100644 --- a/tasks/python.yml +++ b/tasks/python.yml @@ -12,7 +12,7 @@ copy: src=get-pip.py dest=/usr/share/python/get-pip.py - 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 @@ -28,34 +28,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 - pip: - virtualenv: "{{ item.path }}" - virtualenv_python: "{{ item.python|default('python') }}" - virtualenv_site_packages: false - with_items: "{{ python_virtualenvs }}" + shell: virtualenv {{item.path}} --python={{item.python|default('python')}} + args: + creates: "{{item.path}}" + with_items: "{{python_virtualenvs}}" tags: - venv environment: - PATH: "{{ ansible_env.PATH }}:{{ ansible_user_dir }}/.local/bin" + PATH: "{{ansible_env.PATH}}:{{ansible_user_dir}}/.local/bin" when: "python_virtualenv_user is not defined" - name: Setup virtualenvs for specific user - pip: - virtualenv: "{{ item.path }}" - virtualenv_python: "{{ item.python|default('python') }}" - virtualenv_site_packages: false - with_items: "{{ python_virtualenvs }}" + shell: virtualenv {{item.path}} --python={{item.python|default('python')}} + args: + creates: "{{item.path}}" + with_items: "{{python_virtualenvs}}" tags: - venv environment: - PATH: "{{ ansible_env.PATH }}:{{ ansible_user_dir }}/.local/bin" - become_user: "{{ item.user|default(python_virtualenv_user) }}" + PATH: "{{ansible_env.PATH}}:{{ansible_user_dir}}/.local/bin" + become_user: "{{item.user|default(python_virtualenv_user)}}" when: "python_virtualenv_user is defined" From e7f5c29356fcd5ac69bf9d1fea64f2de439578c2 Mon Sep 17 00:00:00 2001 From: "Andrieu, Alban" Date: Mon, 15 Mar 2021 10:45:09 +0100 Subject: [PATCH 11/12] Allow to disable pip install --- defaults/main.yml | 1 + tasks/python.yml | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) 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/python.yml b/tasks/python.yml index cf3fb8d..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|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 @@ -50,7 +52,7 @@ shell: virtualenv {{item.path}} --python={{item.python|default('python')}} args: creates: "{{item.path}}" - with_items: "{{python_virtualenvs}}" + with_items: "{{python_virtualenvs}}" tags: - venv environment: From c50ed88ed35ee9f5fb9637c2bcd381e9bcc18940 Mon Sep 17 00:00:00 2001 From: AlbanAndrieu Date: Mon, 11 Apr 2022 17:43:30 +0200 Subject: [PATCH 12/12] Upgrade from 2.7 to 3.6 --- .travis.yml | 12 ++++++------ tasks/install.deb.yml | 14 ++++++++++++-- test.yml | 6 +++++- 3 files changed, 23 insertions(+), 9 deletions(-) diff --git a/.travis.yml b/.travis.yml index e16d16a..e7226b5 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,8 +1,8 @@ --- language: python python: - - "2.7" -# - "3.4" +# - "2.7" + - "3.6" env: - ANSIBLE_VERSION=latest @@ -52,8 +52,8 @@ 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 @@ -63,6 +63,6 @@ script: #- 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.14/bin +#python_pkg_bin: /home/travis/virtualenv/python2.7.14/bin diff --git a/tasks/install.deb.yml b/tasks/install.deb.yml index df85883..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 }}" 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