diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 7e2bc34..70e6297 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -44,14 +44,14 @@ jobs: fail-fast: false matrix: include: - - distro: debian8 - - distro: debian9 - distro: debian10 - - distro: ubuntu1604 - ansible-version: '>=2.10, <2.11' - - distro: ubuntu1604 + - distro: debian11 + - distro: debian12 - distro: ubuntu1804 + ansible-version: '>=9, <10' - distro: ubuntu2004 + - distro: ubuntu2204 + - distro: ubuntu2404 steps: - name: Check out the codebase @@ -65,8 +65,8 @@ jobs: python-version: '3.x' - name: Install test dependencies - run: pip install 'ansible${{ matrix.ansible-version }}' molecule-plugins[docker] docker - + run: | + pip install 'ansible${{ matrix.ansible-version }}' molecule-plugins[docker] docker - name: Run Molecule tests run: | molecule test diff --git a/README.md b/README.md index 9ab2b6e..740d4c6 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ [![CI](https://github.com/Oefenweb/ansible-pip/workflows/CI/badge.svg)](https://github.com/Oefenweb/ansible-pip/actions?query=workflow%3ACI) [![Ansible Galaxy](http://img.shields.io/badge/ansible--galaxy-pip-blue.svg)](https://galaxy.ansible.com/Oefenweb/pip) -Set up (the latest version of) [pip](https://pypi.python.org/pypi/pip), [wheel](https://packaging.python.org/key_projects/#wheel) and [setuptools](https://packaging.python.org/key_projects/#setuptools) in Debian-like systems. +Set up (the latest version of) [pip](https://pypi.python.org/pypi/pip) in Debian-like systems. #### Requirements @@ -11,10 +11,15 @@ Set up (the latest version of) [pip](https://pypi.python.org/pypi/pip), [wheel]( * `python(2|3)-dev` (will be installed) * `curl` (will be installed) +when using `pip_install_method: get-pip` + #### Variables -* `pip_python_version_major` [default: `2`]: Python version to install `pip` for. -* `pip_python_version` [default: `pip_python_version`]: Deprecated +* `pip_install_method`: [default: `native`]: The way to install `pip` (e.g. `native` (from Ubuntu/Debian repo) or `get-pip`, `< 24.04` only) + +* `pip_python_version_major` [default: `3`]: Python version to install `pip` for + +* `pip_install`: [default: `[]`]: Additional packages to install ## Dependencies diff --git a/Vagrantfile b/Vagrantfile index a0182a0..e86d32d 100644 --- a/Vagrantfile +++ b/Vagrantfile @@ -4,13 +4,6 @@ role = File.basename(File.expand_path(File.dirname(__FILE__))) boxes = [ - { - :name => "ubuntu-1604", - :box => "bento/ubuntu-16.04", - :ip => '10.0.0.12', - :cpu => "50", - :ram => "256" - }, { :name => "ubuntu-1804", :box => "bento/ubuntu-18.04", @@ -23,21 +16,21 @@ boxes = [ :box => "bento/ubuntu-20.04", :ip => '10.0.0.14', :cpu => "50", - :ram => "384" + :ram => "512" }, { - :name => "debian-8", - :box => "bento/debian-8", - :ip => '10.0.0.16', + :name => "ubuntu-2204", + :box => "bento/ubuntu-22.04", + :ip => '10.0.0.15', :cpu => "50", - :ram => "256" + :ram => "512" }, { - :name => "debian-9", - :box => "bento/debian-9", - :ip => '10.0.0.17', + :name => "ubuntu-2404", + :box => "bento/ubuntu-24.04", + :ip => '10.0.0.16', :cpu => "50", - :ram => "256" + :ram => "512" }, { :name => "debian-10", @@ -46,6 +39,20 @@ boxes = [ :cpu => "50", :ram => "256" }, + { + :name => "debian-11", + :box => "bento/debian-11", + :ip => '10.0.0.19', + :cpu => "50", + :ram => "256" + }, + { + :name => "debian-12", + :box => "bento/debian-12", + :ip => '10.0.0.20', + :cpu => "50", + :ram => "384" + }, ] Vagrant.configure("2") do |config| diff --git a/defaults/main.yml b/defaults/main.yml index f140ab3..8dac3fa 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -1,4 +1,10 @@ # defaults file --- -pip_python_version_major: 2 +pip_install_method: native +# Only available for < 24.04 +# pip_install_method: get-pip + +pip_python_version_major: 3 pip_python_version: "{{ pip_python_version_major }}" + +pip_install: [] diff --git a/meta/main.yml b/meta/main.yml index ccb21d7..c7d8944 100644 --- a/meta/main.yml +++ b/meta/main.yml @@ -1,9 +1,8 @@ # meta file --- galaxy_info: - namespace: oefenweb + author: oefenweb role_name: pip - author: Mischa ter Smitten company: Oefenweb.nl B.V. description: Set up (the latest version of) pip, setuptools and wheel in Debian-like systems license: MIT @@ -11,14 +10,15 @@ galaxy_info: platforms: - name: Ubuntu versions: - - xenial - bionic - focal + - jammy + - noble - name: Debian versions: - - jessie - - stretch - buster + - bullseye + - bookworm galaxy_tags: - development - system diff --git a/molecule/default/collections.yml b/molecule/default/collections.yml index c3d7e2a..1062b36 100644 --- a/molecule/default/collections.yml +++ b/molecule/default/collections.yml @@ -1,6 +1,2 @@ --- -collections: - - name: community.docker - version: '>=1.2.0,<2' - - name: community.general - version: '>=2,<3' +collections: [] diff --git a/molecule/default/molecule.yml b/molecule/default/molecule.yml index 8841165..908aaf6 100644 --- a/molecule/default/molecule.yml +++ b/molecule/default/molecule.yml @@ -5,7 +5,7 @@ driver: name: docker platforms: - name: instance - image: "geerlingguy/docker-${MOLECULE_DISTRO:-ubuntu1604}-ansible:latest" + image: "geerlingguy/docker-${MOLECULE_DISTRO:-ubuntu2004}-ansible:latest" command: ${MOLECULE_DOCKER_COMMAND:-""} volumes: - /sys/fs/cgroup:/sys/fs/cgroup:rw diff --git a/tasks/install-get-pip.yml b/tasks/install-get-pip.yml new file mode 100644 index 0000000..521b2bf --- /dev/null +++ b/tasks/install-get-pip.yml @@ -0,0 +1,113 @@ +# tasks file +--- +- name: install | get-pip | install dependencies + ansible.builtin.apt: + name: "{{ pip_install_get_pip_dependencies }}" + state: "{{ apt_install_state | default('latest') }}" + update_cache: true + cache_valid_time: "{{ apt_update_cache_valid_time | default(3600) }}" + tags: + - pip-install-get-pip-dependencies + +- name: install | get-pip | create (download) directory + ansible.builtin.file: + path: "{{ pip_install_get_pip_download_path }}" + state: directory + owner: root + group: root + mode: 0755 + tags: + - pip-install-get-pip-directory + +- name: install | get-pip | get python version # noqa risky-shell-pipe + ansible.builtin.shell: > + python{{ pip_python_version_major | string }} --version 2>&1 | awk '{print $2}' + register: _python_version + changed_when: false + tags: + - pip-install-get-pip-get-python-version + +- name: install | get-pip | get download url + tags: + - pip-install-get-pip-get-download-url + block: + - name: install | get-pip | get download url (2.6) + ansible.builtin.set_fact: + pip_download_url: 'https://bootstrap.pypa.io/pip/2.6/get-pip.py' + when: + - _python_version.stdout is version('2.6', '>=') + - _python_version.stdout is version('2.7', '<') + + - name: install | get-pip | get download url (2.7) + ansible.builtin.set_fact: + pip_download_url: 'https://bootstrap.pypa.io/pip/2.7/get-pip.py' + when: + - _python_version.stdout is version('2.7', '>=') + - _python_version.stdout is version('2.8', '<') + + - name: install | get-pip | get download url (3.2) + ansible.builtin.set_fact: + pip_download_url: 'https://bootstrap.pypa.io/pip/3.2/get-pip.py' + when: + - _python_version.stdout is version('3.2', '>=') + - _python_version.stdout is version('3.3', '<') + + - name: install | get-pip | get download url (3.3) + ansible.builtin.set_fact: + pip_download_url: 'https://bootstrap.pypa.io/pip/3.3/get-pip.py' + when: + - _python_version.stdout is version('3.3', '>=') + - _python_version.stdout is version('3.4', '<') + + - name: install | get-pip | get download url (3.4) + ansible.builtin.set_fact: + pip_download_url: 'https://bootstrap.pypa.io/pip/3.4/get-pip.py' + when: + - _python_version.stdout is version('3.4', '>=') + - _python_version.stdout is version('3.5', '<') + + - name: install | get-pip | get download url (3.5) + ansible.builtin.set_fact: + pip_download_url: 'https://bootstrap.pypa.io/pip/3.5/get-pip.py' + when: + - _python_version.stdout is version('3.5', '>=') + - _python_version.stdout is version('3.6', '<') + + - name: install | get-pip | get download url (3.6) + ansible.builtin.set_fact: + pip_download_url: 'https://bootstrap.pypa.io/pip/3.6/get-pip.py' + when: + - _python_version.stdout is version('3.6', '>=') + - _python_version.stdout is version('3.7', '<') + + - name: install | get-pip | get download url (3.7) + ansible.builtin.set_fact: + pip_download_url: 'https://bootstrap.pypa.io/pip/3.7/get-pip.py' + when: + - _python_version.stdout is version('3.7', '>=') + - _python_version.stdout is version('3.8', '<') + + - name: install | get-pip | get download url (latest) + ansible.builtin.set_fact: + pip_download_url: 'https://bootstrap.pypa.io/pip/get-pip.py' + when: _python_version.stdout is version('3.8', '>=') + +- name: install | get-pip | download (latest) + ansible.builtin.get_url: + url: "{{ pip_download_url }}" + dest: "{{ pip_install_get_pip_download_path }}/{{ pip_download_url | basename }}-{{ pip_python_version_major | string }}" + owner: root + group: root + mode: 0644 + force: true + register: _download_latest + tags: + - pip-install-get-pip-download + +- name: install | get-pip | install (latest) + ansible.builtin.command: > + python{{ pip_python_version_major | string }} {{ _download_latest.dest }} + when: _download_latest is changed + changed_when: true + tags: + - pip-install-get-pip-install diff --git a/tasks/install-native.yml b/tasks/install-native.yml new file mode 100644 index 0000000..4cbae3b --- /dev/null +++ b/tasks/install-native.yml @@ -0,0 +1,10 @@ +# tasks file +--- +- name: install | native | dependencies + ansible.builtin.apt: + name: "{{ pip_install_native_dependencies }}" + state: "{{ apt_install_state | default('latest') }}" + update_cache: true + cache_valid_time: "{{ apt_update_cache_valid_time | default(3600) }}" + tags: + - pip-install-native-dependencies diff --git a/tasks/main.yml b/tasks/main.yml index befd406..ec8f3f3 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -1,118 +1,37 @@ # tasks file --- -- name: install dependencies - ansible.builtin.apt: - name: "{{ pip_dependencies }}" - state: "{{ apt_install_state | default('latest') }}" - update_cache: true - cache_valid_time: "{{ apt_update_cache_valid_time | default(3600) }}" - tags: - - configuration - - pip - - pip-dependencies - -- name: create (download) directory - ansible.builtin.file: - path: "{{ pip_download_path }}" - state: directory - owner: root - group: root - mode: 0755 - tags: - - configuration - - pip - - pip-directory - -- name: get python version # noqa risky-shell-pipe - ansible.builtin.shell: > - python{{ pip_python_version_major | string }} --version 2>&1 | awk '{print $2}' - register: _python_version - changed_when: false +- name: install native + ansible.builtin.import_tasks: install-native.yml + when: pip_install_method == 'native' tags: - configuration - pip - - pip-get-python-version + - pip-install-native -- name: get download url +- name: install pip + ansible.builtin.import_tasks: install-get-pip.yml + when: pip_install_method == 'get-pip' tags: - configuration - pip - - pip-get-download-url - block: - - name: get download url (2.6) - ansible.builtin.set_fact: - pip_download_url: 'https://bootstrap.pypa.io/pip/2.6/get-pip.py' - when: - - _python_version.stdout is version('2.6', '>=') - - _python_version.stdout is version('2.7', '<') + - pip-install-get-pip - - name: get download url (2.7) - ansible.builtin.set_fact: - pip_download_url: 'https://bootstrap.pypa.io/pip/2.7/get-pip.py' - when: - - _python_version.stdout is version('2.7', '>=') - - _python_version.stdout is version('2.8', '<') - - - name: get download url (3.2) - ansible.builtin.set_fact: - pip_download_url: 'https://bootstrap.pypa.io/pip/3.2/get-pip.py' - when: - - _python_version.stdout is version('3.2', '>=') - - _python_version.stdout is version('3.3', '<') - - - name: get download url (3.3) - ansible.builtin.set_fact: - pip_download_url: 'https://bootstrap.pypa.io/pip/3.3/get-pip.py' - when: - - _python_version.stdout is version('3.3', '>=') - - _python_version.stdout is version('3.4', '<') - - - name: get download url (3.4) - ansible.builtin.set_fact: - pip_download_url: 'https://bootstrap.pypa.io/pip/3.4/get-pip.py' - when: - - _python_version.stdout is version('3.4', '>=') - - _python_version.stdout is version('3.5', '<') - - - name: get download url (3.5) - ansible.builtin.set_fact: - pip_download_url: 'https://bootstrap.pypa.io/pip/3.5/get-pip.py' - when: - - _python_version.stdout is version('3.5', '>=') - - _python_version.stdout is version('3.6', '<') - - - name: get download url (3.6) - ansible.builtin.set_fact: - pip_download_url: 'https://bootstrap.pypa.io/pip/3.6/get-pip.py' - when: - - _python_version.stdout is version('3.6', '>=') - - _python_version.stdout is version('3.7', '<') - - - name: get download url (latest) - ansible.builtin.set_fact: - pip_download_url: 'https://bootstrap.pypa.io/pip/get-pip.py' - when: _python_version.stdout is version('3.7', '>=') - -- name: download (latest) pip - ansible.builtin.get_url: - url: "{{ pip_download_url }}" - dest: "{{ pip_download_path }}/{{ pip_download_url | basename }}-{{ pip_python_version_major | string }}" - owner: root - group: root - mode: 0644 - force: true - register: _download_latest +- name: install additional + ansible.builtin.apt: + name: "{{ pip_install }}" + state: "{{ apt_install_state | default('latest') }}" tags: - configuration - pip - - pip-pip-download + - pip-install + - pip-install-additional -- name: install (latest) pip (setuptools and wheel) +- name: verify ansible.builtin.command: > - python{{ pip_python_version_major | string }} {{ _download_latest.dest }} - when: _download_latest is changed - changed_when: true + pip --version + changed_when: false tags: - configuration - pip - - pip-pip-install + - pip-install + - pip-install-verify diff --git a/tests/vars/_default.yml b/tests/vars/_default.yml index b4ed3de..c09e799 100644 --- a/tests/vars/_default.yml +++ b/tests/vars/_default.yml @@ -1,3 +1,3 @@ # vars file --- -pip_python_version_major: 3 +pip_install_method: get-pip diff --git a/tests/vars/_jessie.yml b/tests/vars/_jessie.yml deleted file mode 100644 index c80ba89..0000000 --- a/tests/vars/_jessie.yml +++ /dev/null @@ -1,3 +0,0 @@ -# vars file ---- -pip_python_version_major: 2 diff --git a/tests/vars/_noble.yml b/tests/vars/_noble.yml new file mode 100644 index 0000000..013be4c --- /dev/null +++ b/tests/vars/_noble.yml @@ -0,0 +1,3 @@ +# vars file +--- +pip_install_method: native diff --git a/tests/vars/_stretch.yml b/tests/vars/_stretch.yml deleted file mode 100644 index c80ba89..0000000 --- a/tests/vars/_stretch.yml +++ /dev/null @@ -1,3 +0,0 @@ -# vars file ---- -pip_python_version_major: 2 diff --git a/tests/vars/_xenial.yml b/tests/vars/_xenial.yml deleted file mode 100644 index c80ba89..0000000 --- a/tests/vars/_xenial.yml +++ /dev/null @@ -1,3 +0,0 @@ -# vars file ---- -pip_python_version_major: 2 diff --git a/vars/main.yml b/vars/main.yml index 9588ef9..33e360b 100644 --- a/vars/main.yml +++ b/vars/main.yml @@ -1,8 +1,11 @@ # vars file --- -pip_dependencies: +pip_install_native_dependencies: + - "python{{ pip_python_version_major is version('3', '>=') | ternary('3', '') }}-pip" + +pip_install_get_pip_dependencies: - "python{{ pip_python_version_major is version('3', '>=') | ternary('3', '') }}" - "python{{ pip_python_version_major is version('3', '>=') | ternary('3', '') }}-dev" - curl -pip_download_path: /var/lib/ansible/pip/downloads +pip_install_get_pip_download_path: /var/lib/ansible/pip/downloads