- hosts: localhost
  tasks:

  - name: Install Apt Packages for Entertainment
    become: yes
    apt:
      state: present
      name:
        - freetuxtv
        - hypnotix
        - celluloid
        - transmission-gtk
        - vlc
    tags:
      - entertainment
      - never

  - name: Install Apt Packages for Games
    become: yes
    apt:
      state: present
      name:
        - openjdk-11-jre
    tags:
      - games
      - never

  - name: Flatpak Install Stremio
    command: flatpak install --assumeyes flathub com.stremio.Stremio
    args:
      creates: /home/{{ ansible_env.USER }}/Desktop/com.stremio.Stremio
    tags:
      - entertainment
      - never

  - name: Flatpak Install Clementine
    command: flatpak install --assumeyes flathub org.clementine_player.Clementine
    args:
      creates: /home/{{ ansible_env.USER }}/.var/app/org.clementine_player.Clementine
    tags:
      - entertainment
      - never

  - name: Flatpak Install Joystick Utilities
    command: flatpak install --assumeyes flathub io.gitlab.jstest_gtk.jstest_gtk
    args:
      creates: /home/{{ ansible_env.USER }}/.var/app/io.gitlab.jstest_gtk.jstest_gtk
    tags:
      - entertainment
      - games
      - never

  - name: Flatpak Install Spotify
    command: flatpak install --assumeyes flathub com.spotify.Client
    args:
      creates: /home/{{ ansible_env.USER }}/.var/app/com.spotify.Client
    tags:
      - entertainment
      - never

  - name: Flatpak Install Heroic Games Launcher
    command: flatpak install --assumeyes flathub com.heroicgameslauncher.hgl
    args:
      creates: /home/{{ ansible_env.USER }}/.var/app/com.heroicgameslauncher.hgl
    tags:
      - games
      - never

  - name: Flatpak Install Steam
    command: flatpak install --assumeyes flathub com.valuesoftware.Steam
    args:
      creates: /home/{{ ansible_env.USER }}/.var/app/com.valuesoftware.Steam
    when: ansible_facts['lsb']['release'] > "20.00"
    tags:
      - games
      - never

  - name: Package Install Steam
    become: yes
    apt:
      state: present
      name:
        - steam-launcher
    when: ansible_facts['lsb']['release'] < "20.00"
    tags:
      - games
      - never

  - name: Flatpak Install 0 A.D.
    command: flatpak install --assumeyes flathub com.play0ad.zeroad
    args:
      creates: /home/{{ ansible_env.USER }}/.var/app/com.play0ad.zeroad
    tags:
      - games
      - never

  - name: Flatpak Stunt Rally
    command: flatpak install --assumeyes flathub org.tuxfamily.StuntRally
    args:
      creates: /home/{{ ansible_env.USER }}/.var/app/org.tuxfamily.StuntRally
    tags:
      - games
      - never

  - name: Flatpak MineTest
    command: flatpak install --assumeyes flathub net.minetest.Minetest
    args:
      creates: /home/{{ ansible_env.USER }}/.var/app/net.minetest.Minetest
    tags:
      - games
      - never

  - name: Flatpak Extreme Tuxracer
    command: flatpak install --assumeyes flathub net.sourceforge.ExtremeTuxRacer
    args:
      creates: /home/{{ ansible_env.USER }}/.var/app/net.sourceforge.ExtremeTuxRacer
    tags:
      - games
      - never

  - name: Flatpak SuperTux
    command: flatpak install --assumeyes flathub org.supertuxproject.SuperTux
    args:
      creates: /home/{{ ansible_env.USER }}/.var/app/org.supertuxproject.SuperTux
    tags:
      - games
      - never

  - name: Flatpak SuperTuxKart
    command: flatpak install --assumeyes flathub net.supertuxkart.SuperTuxKart
    args:
      creates: /home/{{ ansible_env.USER }}/.var/app/org.supertuxproject.SuperTux
    tags:
      - games
      - never


  - name: Setup yuzu make dir
    file:
      path: /tmp/yuzu
      state: directory
      force: no
    tags:
      - gamesx
      - never

  - name: Get yuzu tarball from github
    get_url:
      url: https://github.com/yuzu-emu/liftinstall/releases/download/1.0/liftinstall-0cbfda0.tar.xz
      dest: /tmp/yuzu
    tags:
      - gamesx
      - never

  - name: Expand the tarball
    unarchive:
      src: /tmp/yuzu/liftinstall-0cbfda0.tar.xz
      dest: /tmp/yuzu/
      owner: "{{ ansible_env.USER }}"
      group: "{{ ansible_env.USER }}"
      remote_src: true
    tags:
      - gamesx
      - never


  - name: Install the tarball
    command: ./liftinstall
    args:
      chdir: /tmp/yuzu/
    tags:
      - gamesx
      - never


  - name: Install Apt Packages for Plex
    become: yes
    apt:
      state: present
      name:
        - apt-transport-https
    tags:
      - plex
      - never

  - name: "Add PlexSign apt key"
    become: yes
    apt_key:
      url: https://downloads.plex.tv/plex-keys/PlexSign.key
      state: present
    tags:
      - plex
      - never

  - name: "Add Plex apt repo"
    become: yes
    apt_repository:
      repo: deb https://downloads.plex.tv/repo/deb public main 
      update_cache: yes
    tags:
      - plex
      - never

  - name: Install Apt Packages for Plex Media Server
    become: yes
    apt:
      state: present
      name:
        - plexmediaserver
    tags:
      - plex
      - never

  - name: Start Plex at boot time
    become: yes
    command: systemctl start plexmediaserver
    tags:
      - plex
      - never

  - name: Setup Plex at boot time
    become: yes
    command: systemctl enable plexmediaserver
    tags:
      - plex
      - never
