---
- name: Gnome desktop setup
  hosts: all
  user: root

  tasks:
    - name: Enable autologin
      copy:
        src: 'files/desktop/autologin'
        dest: '/etc/gdm/custom.conf'

    - name: Pin applications to dash
      copy:
        src: 'files/desktop/dash'
        dest: '/etc/dconf/db/local.d/dash'

    - name: Set wallpaper
      copy: src={{ item.src }} dest={{ item.dest }}
      with_items:
        - { src: 'files/desktop/background', dest: '/etc/dconf/db/local.d/background' }
        - { src: 'files/desktop/wallpaper.jpg', dest: '/usr/local/share/wallpaper.jpg' }

    - name: Remove old wallpaper config
      # This can be deleted in the future
      file:
        path: '/etc/dconf/db/local.d/wallpaper'
        state: absent

    - name: Lock desktop wallpaper settings
      copy:
        src: 'files/desktop/lock/background'
        dest: '/etc/dconf/db/local.d/locks/background'

    - name: GDM usernames profile
      copy:
        src: 'files/desktop/profile'
        dest: '/etc/dconf/profile/gdm'

    - name: GDM login screen configuration - don't show all users
      copy:
        src: 'files/desktop/login-screen'
        dest: '/etc/dconf/db/gdm.d/login-screen'

    - name: GDM login screen configuration - disable accessibility
      # Not working, perhaps broken GDM
      copy:
        src: 'files/desktop/accessibility'
        dest: '/etc/dconf/db/gdm.d/accessibility'

    - name: GDM screensaver with short delay
      copy:
        src: 'files/desktop/screensaver-short'
        dest: '/etc/dconf/db/local.d/screensaver'

    - name: GDM screensaver with long delay
      when: inventory_hostname in groups['teacher:children']
      copy:
        src: 'files/desktop/screensaver-long'
        dest: '/etc/dconf/db/local.d/screensaver'

    - name: Update dconf database
      command: "dconf update"
