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/tasks | |
| parent | 3995eead6f1e79353547c8437ec2586adf7fd055 (diff) | |
Refactor python and ansible roles to use uv package manager
Diffstat (limited to 'roles/ansible/tasks')
| -rw-r--r-- | roles/ansible/tasks/main.yml | 74 |
1 files changed, 16 insertions, 58 deletions
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 }}" |
