From 9e1ea7b6977331afa635828b0b47935c55a18e80 Mon Sep 17 00:00:00 2001 From: staticdev Date: Mon, 10 Jul 2023 08:32:10 +0200 Subject: [PATCH 1/2] Fix pipx install for Debian 12 --- meta/main.yml | 1 + tasks/custom_facts.yml | 4 ++ tasks/main.yml | 151 +++++++++++++++++++++-------------------- 3 files changed, 84 insertions(+), 72 deletions(-) create mode 100644 tasks/custom_facts.yml diff --git a/meta/main.yml b/meta/main.yml index bec6a61..4cb9be5 100644 --- a/meta/main.yml +++ b/meta/main.yml @@ -29,6 +29,7 @@ galaxy_info: - pyenv - pipx - precommit + - tox - workstation dependencies: diff --git a/tasks/custom_facts.yml b/tasks/custom_facts.yml new file mode 100644 index 0000000..dd52727 --- /dev/null +++ b/tasks/custom_facts.yml @@ -0,0 +1,4 @@ +--- +- name: Set command path based on distribution + ansible.builtin.set_fact: + pipx_path: "{{ '/usr/bin' if ansible_distribution_release == 'bookworm' else ansible_env.HOME + '/.local/bin' }}" diff --git a/tasks/main.yml b/tasks/main.yml index 5a0da0e..97ed1a5 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -1,4 +1,7 @@ --- +- name: Load custom facts + ansible.builtin.import_tasks: custom_facts.yml + - name: Install pyenv ansible.builtin.import_role: name: staticdev.pyenv @@ -17,87 +20,91 @@ - python3-venv # needed for nox - name: Check if pipx is installed - ansible.builtin.command: "{{ ansible_env.HOME }}/.local/bin/pipx --version" + ansible.builtin.command: "{{ pipx_path }}/pipx --version" register: pipx_version_cmd changed_when: false ignore_errors: true -- name: Install pipx +- name: Install pipx on Debian Bookworm + ansible.builtin.package: + name: pipx + when: pipx_version_cmd is failed and ansible_distribution_release == 'bookworm' + +- name: Install pipx on non-Bookworm OS ansible.builtin.pip: name: pipx extra_args: --user - when: pipx_version_cmd is failed + when: pipx_version_cmd is failed and ansible_distribution_release != 'bookworm' +# - name: Check if pre-commit is installed +# ansible.builtin.command: "{{ ansible_env.HOME }}/.local/bin/pre-commit --version" +# register: pre_commit_check +# changed_when: false +# ignore_errors: true -- name: Check if pre-commit is installed - ansible.builtin.command: "{{ ansible_env.HOME }}/.local/bin/pre-commit --version" - register: pre_commit_check - changed_when: false - ignore_errors: true +# - name: Install pre-commit +# ansible.builtin.command: "{{ ansible_env.HOME }}/.local/bin/pipx install pre-commit" +# register: output +# changed_when: "output.rc == 0" +# when: pre_commit_check is failed -- name: Install pre-commit - ansible.builtin.command: "{{ ansible_env.HOME }}/.local/bin/pipx install pre-commit" - register: output - changed_when: "output.rc == 0" - when: pre_commit_check is failed - -- name: Check if cookiecutter is installed - ansible.builtin.stat: - path: "{{ ansible_env.HOME }}/.local/pipx/venvs/cookiecutter" - register: cookiecutter_folder_check - -- name: Install cookiecutter - ansible.builtin.command: "{{ ansible_env.HOME }}/.local/bin/pipx install cookiecutter" - register: output - changed_when: "output.rc == 0" - when: cookiecutter_folder_check is failed - -- name: Check if poetry is installed - ansible.builtin.command: "{{ ansible_env.HOME }}/.local/bin/poetry" - register: poetry_cmd - changed_when: false - ignore_errors: true +# - name: Check if cookiecutter is installed +# ansible.builtin.stat: +# path: "{{ ansible_env.HOME }}/.local/pipx/venvs/cookiecutter" +# register: cookiecutter_folder_check -- name: Download poetry installer - ansible.builtin.get_url: - url: https://install.python-poetry.org - dest: "{{ ansible_env.HOME }}/install-poetry.py" - mode: "0400" - timeout: 20 - when: poetry_cmd is failed - notify: Delete poetry installer - -- name: Install poetry - ansible.builtin.command: "python3 {{ ansible_env.HOME }}/install-poetry.py" - register: output - changed_when: "output.rc == 0" - when: poetry_cmd is failed - -- name: Check if nox is installed - ansible.builtin.command: "{{ ansible_env.HOME }}/.local/bin/nox --version" - register: nox_version_cmd - changed_when: false - ignore_errors: true +# - name: Install cookiecutter +# ansible.builtin.command: "{{ ansible_env.HOME }}/.local/bin/pipx install cookiecutter" +# register: output +# changed_when: "output.rc == 0" +# when: cookiecutter_folder_check is failed -- name: Install nox - ansible.builtin.command: "{{ ansible_env.HOME }}/.local/bin/pipx install nox" - register: output - changed_when: "output.rc == 0" - when: nox_version_cmd is failed - -- name: Install nox-poetry - ansible.builtin.command: "{{ ansible_env.HOME }}/.local/bin/pipx inject nox nox-poetry" - register: output - changed_when: "output.rc == 0" - when: nox_version_cmd is failed - -- name: Check if tox is installed - ansible.builtin.command: "{{ ansible_env.HOME }}/.local/bin/tox --version" - register: tox_version_cmd - changed_when: false - ignore_errors: true +# - name: Check if poetry is installed +# ansible.builtin.command: "{{ ansible_env.HOME }}/.local/bin/poetry" +# register: poetry_cmd +# changed_when: false +# ignore_errors: true + +# - name: Download poetry installer +# ansible.builtin.get_url: +# url: https://install.python-poetry.org +# dest: "{{ ansible_env.HOME }}/install-poetry.py" +# mode: "0400" +# timeout: 20 +# when: poetry_cmd is failed +# notify: Delete poetry installer + +# - name: Install poetry +# ansible.builtin.command: "python3 {{ ansible_env.HOME }}/install-poetry.py" +# register: output +# changed_when: "output.rc == 0" +# when: poetry_cmd is failed + +# - name: Check if nox is installed +# ansible.builtin.command: "{{ ansible_env.HOME }}/.local/bin/nox --version" +# register: nox_version_cmd +# changed_when: false +# ignore_errors: true + +# - name: Install nox +# ansible.builtin.command: "{{ ansible_env.HOME }}/.local/bin/pipx install nox" +# register: output +# changed_when: "output.rc == 0" +# when: nox_version_cmd is failed + +# - name: Install nox-poetry +# ansible.builtin.command: "{{ ansible_env.HOME }}/.local/bin/pipx inject nox nox-poetry" +# register: output +# changed_when: "output.rc == 0" +# when: nox_version_cmd is failed + +# - name: Check if tox is installed +# ansible.builtin.command: "{{ ansible_env.HOME }}/.local/bin/tox --version" +# register: tox_version_cmd +# changed_when: false +# ignore_errors: true -- name: Install tox - ansible.builtin.command: "{{ ansible_env.HOME }}/.local/bin/pipx install tox" - register: output - changed_when: "output.rc == 0" - when: tox_version_cmd is failed +# - name: Install tox +# ansible.builtin.command: "{{ ansible_env.HOME }}/.local/bin/pipx install tox" +# register: output +# changed_when: "output.rc == 0" +# when: tox_version_cmd is failed From f24733717abac7a00786e80914e420f9455076ae Mon Sep 17 00:00:00 2001 From: staticdev Date: Mon, 10 Jul 2023 17:38:06 +0200 Subject: [PATCH 2/2] Uncomment other installations --- tasks/main.yml | 148 +++++++++++++++++++++++++------------------------ 1 file changed, 75 insertions(+), 73 deletions(-) diff --git a/tasks/main.yml b/tasks/main.yml index 97ed1a5..0b374e7 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -35,76 +35,78 @@ name: pipx extra_args: --user when: pipx_version_cmd is failed and ansible_distribution_release != 'bookworm' -# - name: Check if pre-commit is installed -# ansible.builtin.command: "{{ ansible_env.HOME }}/.local/bin/pre-commit --version" -# register: pre_commit_check -# changed_when: false -# ignore_errors: true - -# - name: Install pre-commit -# ansible.builtin.command: "{{ ansible_env.HOME }}/.local/bin/pipx install pre-commit" -# register: output -# changed_when: "output.rc == 0" -# when: pre_commit_check is failed - -# - name: Check if cookiecutter is installed -# ansible.builtin.stat: -# path: "{{ ansible_env.HOME }}/.local/pipx/venvs/cookiecutter" -# register: cookiecutter_folder_check - -# - name: Install cookiecutter -# ansible.builtin.command: "{{ ansible_env.HOME }}/.local/bin/pipx install cookiecutter" -# register: output -# changed_when: "output.rc == 0" -# when: cookiecutter_folder_check is failed - -# - name: Check if poetry is installed -# ansible.builtin.command: "{{ ansible_env.HOME }}/.local/bin/poetry" -# register: poetry_cmd -# changed_when: false -# ignore_errors: true - -# - name: Download poetry installer -# ansible.builtin.get_url: -# url: https://install.python-poetry.org -# dest: "{{ ansible_env.HOME }}/install-poetry.py" -# mode: "0400" -# timeout: 20 -# when: poetry_cmd is failed -# notify: Delete poetry installer - -# - name: Install poetry -# ansible.builtin.command: "python3 {{ ansible_env.HOME }}/install-poetry.py" -# register: output -# changed_when: "output.rc == 0" -# when: poetry_cmd is failed - -# - name: Check if nox is installed -# ansible.builtin.command: "{{ ansible_env.HOME }}/.local/bin/nox --version" -# register: nox_version_cmd -# changed_when: false -# ignore_errors: true - -# - name: Install nox -# ansible.builtin.command: "{{ ansible_env.HOME }}/.local/bin/pipx install nox" -# register: output -# changed_when: "output.rc == 0" -# when: nox_version_cmd is failed - -# - name: Install nox-poetry -# ansible.builtin.command: "{{ ansible_env.HOME }}/.local/bin/pipx inject nox nox-poetry" -# register: output -# changed_when: "output.rc == 0" -# when: nox_version_cmd is failed - -# - name: Check if tox is installed -# ansible.builtin.command: "{{ ansible_env.HOME }}/.local/bin/tox --version" -# register: tox_version_cmd -# changed_when: false -# ignore_errors: true - -# - name: Install tox -# ansible.builtin.command: "{{ ansible_env.HOME }}/.local/bin/pipx install tox" -# register: output -# changed_when: "output.rc == 0" -# when: tox_version_cmd is failed + +- name: Check if pre-commit is installed + ansible.builtin.command: "{{ ansible_env.HOME }}/.local/bin/pre-commit --version" + register: pre_commit_check + changed_when: false + ignore_errors: true + +- name: Install pre-commit + ansible.builtin.command: "{{ pipx_path }}/pipx install pre-commit" + register: output + changed_when: "output.rc == 0" + when: pre_commit_check is failed + +- name: Check if cookiecutter is installed + ansible.builtin.stat: + path: "{{ ansible_env.HOME }}/.local/pipx/venvs/cookiecutter" + register: cookiecutter_folder_check + ignore_errors: true + +- name: Install cookiecutter + ansible.builtin.command: "{{ pipx_path }}/pipx install cookiecutter" + register: output + changed_when: "output.rc == 0" + when: cookiecutter_folder_check is failed + +- name: Check if poetry is installed + ansible.builtin.command: "{{ ansible_env.HOME }}/.local/bin/poetry" + register: poetry_cmd + changed_when: false + ignore_errors: true + +- name: Download poetry installer + ansible.builtin.get_url: + url: https://install.python-poetry.org + dest: "{{ ansible_env.HOME }}/install-poetry.py" + mode: "0400" + timeout: 20 + when: poetry_cmd is failed + notify: Delete poetry installer + +- name: Install poetry + ansible.builtin.command: "python3 {{ ansible_env.HOME }}/install-poetry.py" + register: output + changed_when: "output.rc == 0" + when: poetry_cmd is failed + +- name: Check if nox is installed + ansible.builtin.command: "{{ ansible_env.HOME }}/.local/bin/nox --version" + register: nox_version_cmd + changed_when: false + ignore_errors: true + +- name: Install nox + ansible.builtin.command: "{{ pipx_path }}/pipx install nox" + register: output + changed_when: "output.rc == 0" + when: nox_version_cmd is failed + +- name: Install nox-poetry + ansible.builtin.command: "{{ pipx_path }}/pipx inject nox nox-poetry" + register: output + changed_when: "output.rc == 0" + when: nox_version_cmd is failed + +- name: Check if tox is installed + ansible.builtin.command: "{{ ansible_env.HOME }}/.local/bin/tox --version" + register: tox_version_cmd + changed_when: false + ignore_errors: true + +- name: Install tox + ansible.builtin.command: "{{ pipx_path }}/pipx install tox" + register: output + changed_when: "output.rc == 0" + when: tox_version_cmd is failed