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/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/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 d86593f..ec8f3f3 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -1,125 +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 (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: 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: 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..013be4c 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: native diff --git a/tests/vars/_noble.yml b/tests/vars/_noble.yml new file mode 100644 index 0000000..c09e799 --- /dev/null +++ b/tests/vars/_noble.yml @@ -0,0 +1,3 @@ +# vars file +--- +pip_install_method: get-pip 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