summaryrefslogtreecommitdiffstats
path: root/roles/python
diff options
context:
space:
mode:
authorAhmed AbdelHalim <[email protected]>2025-09-15 18:33:29 +0200
committerAhmed AbdelHalim <[email protected]>2025-09-15 18:48:43 +0200
commite59971ba6ef374b92137ff3a491355c2fe0cfae6 (patch)
treebf9e661cd0a6e243664d30592ff947c1cd7c4455 /roles/python
parent60ed9c38b77f7ee42266321f1976d9011896a1e6 (diff)
Refactor python and ansible roles to use uv package manager
Diffstat (limited to 'roles/python')
-rw-r--r--roles/python/defaults/main.yml1
-rw-r--r--roles/python/meta/argument_specs.yml6
-rw-r--r--roles/python/meta/main.yml2
-rw-r--r--roles/python/tasks/main.yml74
4 files changed, 11 insertions, 72 deletions
diff --git a/roles/python/defaults/main.yml b/roles/python/defaults/main.yml
index b9639318..c6cfa5a4 100644
--- a/roles/python/defaults/main.yml
+++ b/roles/python/defaults/main.yml
@@ -1,3 +1,2 @@
---
-python_global_version: "system"
python_versions: []
diff --git a/roles/python/meta/argument_specs.yml b/roles/python/meta/argument_specs.yml
index b63ec46b..b553455f 100644
--- a/roles/python/meta/argument_specs.yml
+++ b/roles/python/meta/argument_specs.yml
@@ -4,12 +4,8 @@ argument_specs:
short_description: "Install pyenv, pipx and python (versions) on Linux distributions"
description: "Install pyenv, pipx and python (versions) on Linux distributions"
options:
- python_global_version:
- type: "str"
- description: "The pyenv python global version to use, default: system"
- default: "system"
python_versions:
type: "list"
- description: "The python versions to install"
+ description: "The extra python versions to install (system is used by default when available)"
elements: "str"
default: []
diff --git a/roles/python/meta/main.yml b/roles/python/meta/main.yml
index bf7913e2..4cbc7559 100644
--- a/roles/python/meta/main.yml
+++ b/roles/python/meta/main.yml
@@ -3,7 +3,7 @@ dependencies:
- role: "homebrew"
galaxy_info:
author: "a14m"
- description: "Install pyenv, pipx and python (versions) on Linux distributions"
+ description: "Install uv and python (versions) on Linux distributions"
company: "kartoffeln.work GmbH."
license: "MIT"
min_ansible_version: "2.18"
diff --git a/roles/python/tasks/main.yml b/roles/python/tasks/main.yml
index 18313a17..6ae2e387 100644
--- a/roles/python/tasks/main.yml
+++ b/roles/python/tasks/main.yml
@@ -2,85 +2,29 @@
- name: "Include OS-specific variables"
ansible.builtin.include_vars: "{{ ansible_os_family | lower }}.yml"
-- name: "Install pyenv and pipx"
+- name: "Install uv"
community.general.homebrew:
- name:
- - "pyenv"
- - "pipx"
+ name: "uv"
state: "present"
-- name: "Add pyenv to shell profile"
+- name: "Add uv to shell profile"
ansible.builtin.blockinfile:
path: "{{ ansible_env.HOME }}/.bashrc"
state: "present"
prepend_newline: true
append_newline: true
- marker: "# ==== {mark} ANSIBLE PYENV CONFIG"
+ marker: "# ==== {mark} ANSIBLE UV PYTHON CONFIG"
block: |
- if command -v pyenv 1>/dev/null 2>&1; then
- export PYENV_ROOT="$HOME/.pyenv"
- export PATH="$PYENV_ROOT/bin:$PATH"
- eval "$(pyenv init - bash)"
+ if command -v uv 1>/dev/null 2>&1; then
+ export PATH="$HOME/.local/bin:$PATH"
fi
-- name: "Add pipx to shell profile"
- ansible.builtin.blockinfile:
- path: "{{ ansible_env.HOME }}/.bashrc"
- state: "present"
- prepend_newline: true
- append_newline: true
- marker: "# ==== {mark} ANSIBLE PIPX CONFIG"
- block: |
- if command -v pipx 1>/dev/null 2>&1; then
- export PATH="$PATH:$HOME/.local/bin"
- fi
-
-- name: "Get installed python versions"
- ansible.builtin.command:
- cmd: "pyenv versions --bare"
- environment:
- PATH: "/home/linuxbrew/.linuxbrew/bin:{{ ansible_env.PATH }}"
- register: python_installed_versions
- changed_when: false
- failed_when: false
-
-- name: "Remove unwanted python versions"
- vars:
- major_minor: "{{ item | regex_replace('^([0-9]+\\.[0-9]+).*', '\\1') }}"
- ansible.builtin.command:
- cmd: "pyenv uninstall -f {{ item }}"
- environment:
- PATH: "/home/linuxbrew/.linuxbrew/bin:{{ ansible_env.PATH }}"
- loop: "{{ python_installed_versions.stdout_lines | default([]) }}"
- when:
- - python_installed_versions.rc == 0
- - item is regex('^[0-9]+\.[0-9]+')
- - item not in python_versions
- - major_minor not in python_versions
- changed_when: true
-
- name: "Install python versions"
ansible.builtin.command:
- cmd: "pyenv install {{ item }}"
+ cmd: "uv python install {{ item }}"
args:
- creates: "{{ ansible_env.HOME }}/.pyenv/versions/{{ item }}*/bin/python"
+ creates: "{{ ansible_env.HOME }}/.local/share/uv/python/cpython-{{ item }}-*/bin/python"
environment:
PATH: "/home/linuxbrew/.linuxbrew/bin:{{ ansible_env.PATH }}"
with_items: "{{ python_versions }}"
-
-- name: "Set global python version"
- ansible.builtin.command:
- cmd: "pyenv global {{ python_global_version }}"
- environment:
- PATH: "/home/linuxbrew/.linuxbrew/bin:{{ ansible_env.PATH }}"
- # The set global version always run and is always changing the system
- # It's intentional to ignore this task for idempotency test
- changed_when: true
- tags:
- - molecule-idempotence-notest
-
-- name: "Install packaging for community.general.pipx version installs"
- become: true
- ansible.builtin.package:
- name: "{{ python_packaging }}"
- state: "present"
+ when: python_versions | length > 0