- name: Sort service list set_fact: service_list: >- {{ ((status_services + status_services_extra)|list | map('length') | list) | zip(status_services + status_services_extra|list) | list | sort(attribute=0, reverse=true) | map('last') | list }} - debug: var: service_list - name: Install statusservices script template: src: statusservices.j2 dest: /usr/local/bin/statusservices owner: root group: root mode: '0755' when: - service_list|length > 0 - name: Ensure root .bash_profile.local exists ansible.builtin.file: path: /root/.bash_profile.local state: touch owner: root group: root mode: '0640' changed_when: false - name: Add statusservices to .bash_profile.local lineinfile: path: /root/.bash_profile.local line: '/usr/local/bin/statusservices' state: present when: - service_list|length > 0