summaryrefslogtreecommitdiffstats
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
commit2ec86ad900e742311a538ef4221fa786aa9e431c (patch)
treebf9e661cd0a6e243664d30592ff947c1cd7c4455
parent3995eead6f1e79353547c8437ec2586adf7fd055 (diff)
Refactor python and ansible roles to use uv package manager
-rw-r--r--group_vars/all.yml.example3
-rw-r--r--host_vars/archlinux.local.ymlbin347 -> 317 bytes
-rw-r--r--host_vars/ubuntu.local.ymlbin345 -> 315 bytes
-rw-r--r--roles/ansible/defaults/main.yml9
-rw-r--r--roles/ansible/meta/main.yml2
-rw-r--r--roles/ansible/tasks/main.yml74
-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
10 files changed, 31 insertions, 140 deletions
diff --git a/group_vars/all.yml.example b/group_vars/all.yml.example
index 9af5ee4e..94780625 100644
--- a/group_vars/all.yml.example
+++ b/group_vars/all.yml.example
@@ -29,9 +29,8 @@ password_policy_maxrepeat: 3
password_policy_maxclassrepeat: 0
password_policy_gecoscheck: 0
-python_global_version: "system"
python_versions:
- - "3.11"
+ - "3.12"
- "3.13"
wireguard_autostart_connection: "wg-vpn0"
diff --git a/host_vars/archlinux.local.yml b/host_vars/archlinux.local.yml
index e990c597..0ecce1e8 100644
--- a/host_vars/archlinux.local.yml
+++ b/host_vars/archlinux.local.yml
Binary files differ
diff --git a/host_vars/ubuntu.local.yml b/host_vars/ubuntu.local.yml
index ec917612..70668a43 100644
--- a/host_vars/ubuntu.local.yml
+++ b/host_vars/ubuntu.local.yml
Binary files differ
diff --git a/roles/ansible/defaults/main.yml b/roles/ansible/defaults/main.yml
index 75b19f99..42eaab95 100644
--- a/roles/ansible/defaults/main.yml
+++ b/roles/ansible/defaults/main.yml
@@ -1,8 +1,3 @@
---
-ansible_core_default_version: "2.18.7"
-ansible_core_versions:
- - "2.18.7"
-
-molecule_default_version: "25.7.0"
-molecule_versions:
- - "25.7.0"
+ansible_core_version: "2.18.7"
+molecule_version: "25.7.0"
diff --git a/roles/ansible/meta/main.yml b/roles/ansible/meta/main.yml
index 2b3e00f9..ce12b63b 100644
--- a/roles/ansible/meta/main.yml
+++ b/roles/ansible/meta/main.yml
@@ -3,7 +3,7 @@ dependencies:
- role: "python"
galaxy_info:
author: "a14m"
- description: "Install ansible and molecule on Linux distributions"
+ description: "Install ansible and molecule using uv on Linux distributions"
company: "kartoffeln.work GmbH."
license: "MIT"
min_ansible_version: "2.18"
diff --git a/roles/ansible/tasks/main.yml b/roles/ansible/tasks/main.yml
index de04692e..732cfb2e 100644
--- a/roles/ansible/tasks/main.yml
+++ b/roles/ansible/tasks/main.yml
@@ -2,64 +2,22 @@
- name: "Validate version format"
ansible.builtin.assert:
that:
- - item | regex_search('^[0-9]+\\.[0-9]+\\.[0-9]+$') is not none
- msg: "Version '{{ item }}' must be in major.minor.patch format"
- with_items:
- - "{{ (ansible_core_versions + [ansible_core_default_version]) | unique }}"
- - "{{ (molecule_versions + [molecule_default_version]) | unique }}"
+ - ansible_core_version | regex_search('^[0-9]+\\.[0-9]+\\.[0-9]+$') is not none
+ - molecule_version | regex_search('^[0-9]+\\.[0-9]+\\.[0-9]+$') is not none
+ msg: "Version must be in major.minor.patch format"
-- name: "Install ansible core versions with suffixes"
- community.general.pipx:
- name: "ansible-core=={{ item }}"
- state: "present"
- executable: "/home/linuxbrew/.linuxbrew/bin/pipx"
- suffix: "{{ item }}"
- with_items: "{{ (ansible_core_versions + [ansible_core_default_version]) | unique }}"
- # NOTE: pipx module always report the task changed even if it's not.
- tags:
- - molecule-idempotence-notest
-
-- name: "Install molecule versions with suffixes"
- community.general.pipx:
- name: "molecule=={{ item }}"
- state: "present"
- executable: "/home/linuxbrew/.linuxbrew/bin/pipx"
- suffix: "{{ item }}"
- with_items: "{{ (molecule_versions + [molecule_default_version]) | unique }}"
- # NOTE: pipx module always report the task changed even if it's not.
- tags:
- - molecule-idempotence-notest
-
-# NOTE: the default pipx module inject_packages doesn't work with suffix
-- name: "Inject molecule-plugins with docker and podman drivers"
+- name: "Install ansible core"
ansible.builtin.command:
- cmd: "/home/linuxbrew/.linuxbrew/bin/pipx inject molecule{{ item }} 'molecule-plugins[docker,podman]'"
- with_items: "{{ (molecule_versions + [molecule_default_version]) | unique }}"
- register: pipx_inject_result
- changed_when: "'injected package' in pipx_inject_result.stdout"
- failed_when: pipx_inject_result.rc != 0 and 'already exists' not in pipx_inject_result.stderr
+ cmd: "uv tool install ansible-core=={{ ansible_core_version }}"
+ args:
+ creates: "{{ ansible_env.HOME }}/.local/bin/ansible-core"
+ environment:
+ PATH: "/home/linuxbrew/.linuxbrew/bin:{{ ansible_env.PATH }}"
-- name: "Create symlinks for default ansible version"
- ansible.builtin.file:
- src: "{{ ansible_user_dir }}/.local/bin/{{ item }}{{ ansible_core_default_version }}"
- dest: "{{ ansible_user_dir }}/.local/bin/{{ item }}"
- state: "link"
- force: true
- with_items:
- - "ansible"
- - "ansible-playbook"
- - "ansible-galaxy"
- - "ansible-config"
- - "ansible-console"
- - "ansible-doc"
- - "ansible-inventory"
- - "ansible-pull"
- - "ansible-test"
- - "ansible-vault"
-
-- name: "Create symlinks for default molecule version"
- ansible.builtin.file:
- src: "{{ ansible_user_dir }}/.local/bin/molecule{{ molecule_default_version }}"
- dest: "{{ ansible_user_dir }}/.local/bin/molecule"
- state: "link"
- force: true
+- name: "Install molecule"
+ ansible.builtin.command:
+ cmd: "uv tool install molecule=={{ molecule_version }} --with 'molecule-plugins[docker,podman]'"
+ args:
+ creates: "{{ ansible_env.HOME }}/.local/bin/molecule"
+ environment:
+ PATH: "/home/linuxbrew/.linuxbrew/bin:{{ ansible_env.PATH }}"
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