diff --git a/roles/tmux/tasks/main.yml b/roles/tmux/tasks/main.yml index 5bf38c6..031932e 100644 --- a/roles/tmux/tasks/main.yml +++ b/roles/tmux/tasks/main.yml @@ -12,16 +12,17 @@ database: passwd register: all_users -- name: Create a list of home directories for bash and zsh users +- name: Create a list of home directories for bash, zsh and fish users set_fact: - user_home_dirs: "{{ user_home_dirs | default([]) + [item.value[4]] }}" - loop: "{{ all_users.ansible_facts.getent_passwd | dict2items }}" - when: - - item.value[5] in ['/bin/bash', '/bin/zsh', '/usr/bin/bash', '/usr/bin/zsh', '/usr/bin/fish'] - - item.value[0] != 'root' - - item.value[4] is defined - - item.value[4] != '/' - - item.value[4] != '' + user_home_dirs: >- + {{ all_users.ansible_facts.getent_passwd.values() + | selectattr(5, 'in', ['/bin/bash', '/bin/zsh', '/usr/bin/bash', '/usr/bin/fish']) + | rejectattr(0, 'eq', 'root') + | selectattr(4, 'defined') + | rejectattr(4, 'eq', '') + | rejectattr(4, 'eq', '/') + | map(attribute=4) + | list }} - name: Display the list of collected home directories ansible.builtin.debug: @@ -31,8 +32,7 @@ block: - name: Tmux config Play include_tasks: tmux_config.yml - loop: "{{ user_home_dirs }}" - when: item | basename != 'root' and item != '/' and item != '' + loop: "{{ user_home_dirs }}" # ======================================================================== # EXAMPLE: Here is how you can reuse the 'user_home_dirs' list