diff options
| author | Ahmed Abdelhalim <[email protected]> | 2025-09-15 18:33:29 +0200 |
|---|---|---|
| committer | Ahmed Abdelhalim <[email protected]> | 2025-09-15 18:48:43 +0200 |
| commit | 2ec86ad900e742311a538ef4221fa786aa9e431c (patch) | |
| tree | bf9e661cd0a6e243664d30592ff947c1cd7c4455 /roles/ansible | |
| parent | 3995eead6f1e79353547c8437ec2586adf7fd055 (diff) | |
Refactor python and ansible roles to use uv package manager
Diffstat (limited to 'roles/ansible')
| -rw-r--r-- | roles/ansible/defaults/main.yml | 9 | ||||
| -rw-r--r-- | roles/ansible/meta/main.yml | 2 | ||||
| -rw-r--r-- | roles/ansible/tasks/main.yml | 74 |
3 files changed, 19 insertions, 66 deletions
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 }}" |
