diff --git a/config/ansible/main.yml b/config/ansible/main.yml index 251f23a..c817f2f 100644 --- a/config/ansible/main.yml +++ b/config/ansible/main.yml @@ -1,4 +1,5 @@ -- hosts: all +- name: Configure all hosts + hosts: all gather_facts: true tasks: @@ -65,3 +66,6 @@ - name: Include flatpaks tasks ansible.builtin.import_tasks: tasks/flatpaks.yml when: hostname in ['mennos-laptop', 'mennos-desktop'] + + - name: Include pipx tasks + ansible.builtin.import_tasks: tasks/pipx.yml diff --git a/config/ansible/tasks/pipx.yml b/config/ansible/tasks/pipx.yml new file mode 100644 index 0000000..50381e4 --- /dev/null +++ b/config/ansible/tasks/pipx.yml @@ -0,0 +1,24 @@ +- name: List installed pipx packages + ansible.builtin.shell: set -o pipefail && pipx list --short | awk '{print $1}' + register: installed_pipx_packages + changed_when: false + +- name: Define desired pipx packages + ansible.builtin.set_fact: + desired_pipx_packages: + - ansible + - ansible-lint + - shyaml + +- name: Install pipx packages + community.general.pipx: + name: "{{ item }}" + state: present + loop: "{{ desired_pipx_packages }}" + when: item not in installed_pipx_packages.stdout_lines + +- name: Remove undesired pipx packages + community.general.pipx: + name: "{{ item }}" + state: absent + loop: "{{ installed_pipx_packages.stdout_lines | difference(desired_pipx_packages) }}"