---
- name: Dotfiles
  hosts: localhost
  connection: local
  tasks:
    - name: Set default roles
      set_fact:
        roles: "{{ ansible_run_tags != ['all'] and ansible_run_tags or default_roles | difference(ansible_skip_tags | default([])) }}"
      tags:
        - always

    - name: Set desktop roles
      set_fact:
        roles: "{{ (desktop_roles + roles) | difference(ansible_skip_tags | default([])) }}"
      tags:
        - always
      when: system != 'server' and desktop_roles is defined and ansible_run_tags == ['all']

    - name: Prepend system role
      set_fact:
        roles: "{{ ['system'] | difference(roles) + roles }}"
      tags:
        - always

    - name: Display roles
      debug: "var=roles"
      tags:
        - always

    - name: Run roles
      include_role:
        apply:
          tags:
            - "{{ roles_item }}"
        name: "{{ roles_item }}"
      loop_control:
        loop_var: roles_item
      with_items: "{{ roles }}"
      tags:
        - always
