diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 70e6297..d204d7b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -45,6 +45,7 @@ jobs: matrix: include: - distro: debian10 + ansible-version: '>=9, <10' - distro: debian11 - distro: debian12 - distro: ubuntu1804 diff --git a/README.md b/README.md index 15ccfa7..6032f3d 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,7 @@ Set up (the latest version of) virtualenv(wrapper) in Debian-like systems. #### Variables -* `virtualenv_python_version_major` [default: `2`]: Python version to install `supervisor` for. +* `virtualenv_python_version_major` [default: `3`]: Python version to install `virtualenv` for. * `virtualenv_python_version` [default: `virtualenv_python_version`]: Deprecated ## Dependencies diff --git a/defaults/main.yml b/defaults/main.yml index 8c73653..91ffb36 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -1,4 +1,8 @@ # defaults file --- -virtualenv_python_version_major: 2 +virtualenv_install_method: native +# Only available for < 24.04 +# virtualenv_install_method: pip + +virtualenv_python_version_major: 3 virtualenv_python_version: "{{ virtualenv_python_version_major }}" diff --git a/tasks/install-native.yml b/tasks/install-native.yml new file mode 100644 index 0000000..fbbaf6a --- /dev/null +++ b/tasks/install-native.yml @@ -0,0 +1,10 @@ +# tasks file +--- +- name: install | native | install dependencies + ansible.builtin.apt: + name: "{{ virtualenv_install_native_apt_dependencies }}" + state: "{{ apt_install_state | default('latest') }}" + update_cache: true + cache_valid_time: "{{ apt_update_cache_valid_time | default(3600) }}" + tags: + - virtualenv-install-native-install diff --git a/tasks/install-pip.yml b/tasks/install-pip.yml new file mode 100644 index 0000000..f0465ef --- /dev/null +++ b/tasks/install-pip.yml @@ -0,0 +1,18 @@ +# tasks file +--- +- name: install | pip | install dependencies + ansible.builtin.apt: + name: "{{ virtualenv_install_get_pip_apt_dependencies }}" + state: "{{ apt_install_state | default('latest') }}" + update_cache: true + cache_valid_time: "{{ apt_update_cache_valid_time | default(3600) }}" + tags: + - virtualenv-install-pip-dependencies + +- name: install | pip | install (latest) # noqa package-latest + ansible.builtin.pip: + name: "{{ virtualenv_install_get_pip_pip_dependencies }}" + state: latest + executable: "pip{{ virtualenv_python_version_major | string }}" + tags: + - virtualenv-install-pip-install diff --git a/tasks/main.yml b/tasks/main.yml index ada12fa..7555bf0 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -1,23 +1,27 @@ # tasks file --- -- name: install dependencies - ansible.builtin.apt: - name: "{{ virtualenv_dependencies }}" - state: "{{ apt_install_state | default('latest') }}" - update_cache: true - cache_valid_time: "{{ apt_update_cache_valid_time | default(3600) }}" +- name: install | native + ansible.builtin.import_tasks: install-native.yml + when: virtualenv_install_method == 'native' tags: - configuration - virtualenv - - virtualenv-install - - virtualenv-install-dependencies + - virtualenv-install-native + +- name: install | pip + ansible.builtin.import_tasks: install-pip.yml + when: virtualenv_install_method == 'pip' + tags: + - configuration + - virtualenv + - virtualenv-install-pip -- name: install # noqa package-latest - ansible.builtin.pip: - name: "{{ virtualenv_pip_dependencies }}" - state: latest - executable: "pip{{ virtualenv_python_version_major | string }}" +- name: verify + ansible.builtin.command: > + virtualenv --version + changed_when: false tags: - configuration - virtualenv - virtualenv-install + - virtualenv-install-verify diff --git a/tests/tasks/pre.yml b/tests/tasks/pre.yml index 130f8f1..0eb0f4f 100644 --- a/tests/tasks/pre.yml +++ b/tests/tasks/pre.yml @@ -1,28 +1,31 @@ # pre test file --- -- name: pip | check - ansible.builtin.shell: > - which pip - register: _pip_installed - changed_when: false - check_mode: false - failed_when: false - -- name: pip | install - when: _pip_installed.rc != 0 +- name: pip + when: virtualenv_install_method == 'pip' block: - - name: dependencies | install - ansible.builtin.apt: - name: - - "python{{ virtualenv_python_version_major is version('3', '>=') | ternary('3', '') }}" - - curl - state: "{{ apt_install_state | default('latest') }}" - update_cache: true - cache_valid_time: "{{ apt_update_cache_valid_time | default(3600) }}" - - - name: pip | install # noqa command-instead-of-module + - name: pip | check ansible.builtin.shell: > - curl -sL {{ virtualenv_get_pip_url }} | python{{ virtualenv_python_version_major | string }} - + which pip + register: _pip_installed changed_when: false - tags: - - skip_ansible_lint + check_mode: false + failed_when: false + + - name: pip | install + when: _pip_installed.rc != 0 + block: + - name: dependencies | install + ansible.builtin.apt: + name: + - "python{{ virtualenv_python_version_major is version('3', '>=') | ternary('3', '') }}" + - curl + state: "{{ apt_install_state | default('latest') }}" + update_cache: true + cache_valid_time: "{{ apt_update_cache_valid_time | default(3600) }}" + + - name: pip | install # noqa command-instead-of-module + ansible.builtin.shell: > + curl -sL {{ virtualenv_get_pip_url }} | python{{ virtualenv_python_version_major | string }} - + changed_when: false + tags: + - skip_ansible_lint diff --git a/tests/test.yml b/tests/test.yml index e978481..7bc3a4c 100644 --- a/tests/test.yml +++ b/tests/test.yml @@ -1,6 +1,7 @@ # test file --- -- hosts: localhost +- name: converge + hosts: localhost connection: local become: true pre_tasks: diff --git a/tests/vagrant.yml b/tests/vagrant.yml index 28301e7..717e288 100644 --- a/tests/vagrant.yml +++ b/tests/vagrant.yml @@ -1,6 +1,7 @@ # test file --- -- hosts: all +- name: converge + hosts: all remote_user: vagrant become: true pre_tasks: diff --git a/tests/vars/_bionic.yml b/tests/vars/_bionic.yml deleted file mode 100644 index 8f3360c..0000000 --- a/tests/vars/_bionic.yml +++ /dev/null @@ -1,4 +0,0 @@ -# vars file ---- -virtualenv_python_version_major: 3 -virtualenv_get_pip_url: 'https://bootstrap.pypa.io/pip/3.6/get-pip.py' diff --git a/tests/vars/_buster.yml b/tests/vars/_buster.yml deleted file mode 100644 index 5be4387..0000000 --- a/tests/vars/_buster.yml +++ /dev/null @@ -1,4 +0,0 @@ -# vars file ---- -virtualenv_python_version_major: 3 -virtualenv_get_pip_url: 'https://bootstrap.pypa.io/pip/3.7/get-pip.py' diff --git a/tests/vars/_default.yml b/tests/vars/_default.yml index bcc1178..5342728 100644 --- a/tests/vars/_default.yml +++ b/tests/vars/_default.yml @@ -1,4 +1,3 @@ # vars file --- -virtualenv_python_version_major: 3 -virtualenv_get_pip_url: 'https://bootstrap.pypa.io/pip/get-pip.py' +virtualenv_install_method: pip diff --git a/tests/vars/_noble.yml b/tests/vars/_noble.yml new file mode 100644 index 0000000..256e0bb --- /dev/null +++ b/tests/vars/_noble.yml @@ -0,0 +1,3 @@ +# vars file +--- +virtualenv_install_method: native diff --git a/vars/main.yml b/vars/main.yml index 96a61c0..dc6429d 100644 --- a/vars/main.yml +++ b/vars/main.yml @@ -1,8 +1,12 @@ # vars file --- -virtualenv_dependencies: +virtualenv_install_native_apt_dependencies: + - "python{{ virtualenv_python_version_major is version('3', '>=') | ternary('3', '') }}-virtualenv" + - "python{{ virtualenv_python_version_major is version('3', '>=') | ternary('3', '') }}-virtualenvwrapper" + +virtualenv_install_get_pip_apt_dependencies: - "python{{ virtualenv_python_version_major is version('3', '>=') | ternary('3', '') }}" -virtualenv_pip_dependencies: +virtualenv_install_get_pip_pip_dependencies: - virtualenv - virtualenvwrapper