#####################################
### someone's ansible provisioner ###
#####################################
# Part of: https://git.somenet.org/root/pub/somesible.git
# 2017-2026 by someone <someone@somenet.org>
#
---
- name: create kiosk user
  user:
    name: "kiosk"
    home: "/home/kiosk"
#    shell: "/bin/bash"
    createhome: no
    state: present


- name: create kiosk user's homedir
  file:
    path: "/home/kiosk"
    state: directory
    mode: 0770
    owner: "kiosk"
    group: "kiosk"


- name: copy lightdm.conf config
  copy:
    src: "{{item}}"
    dest: "/etc/lightdm/lightdm.conf"
    mode: 0644
    owner: "root"
    group: "root"
  with_first_found:
    - "{{lookup('env','PWD')}}/host_files/{{inventory_hostname}}/{{role_name}}/lightdm.conf"
    - "{{lookup('env','PWD')}}/group_files/{{group_files_group}}/{{role_name}}/lightdm.conf"
    - "{{lookup('env','PWD')}}/group_files/all/{{role_name}}/lightdm.conf"
    - "default/lightdm.conf"


- name: copy kiosk.sh
  copy:
    src: "{{item}}"
    dest: "/etc/kiosk.sh"
    mode: 0755
    owner: "root"
    group: "root"
  with_first_found:
    - "{{lookup('env','PWD')}}/host_files/{{inventory_hostname}}/{{role_name}}/kiosk.sh"
    - "{{lookup('env','PWD')}}/group_files/{{group_files_group}}/{{role_name}}/kiosk.sh"
    - "{{lookup('env','PWD')}}/group_files/all/{{role_name}}/kiosk.sh"
    - "default/kiosk.sh"


- name: copy kiosk.tar.bz2
  copy:
    src: "{{item}}"
    dest: "/etc/kiosk.tar.bz2"
    mode: 0600
    owner: "root"
    group: "root"
  with_first_found:
    - "{{lookup('env','PWD')}}/host_files/{{inventory_hostname}}/{{role_name}}/kiosk.tar.bz2"
    - "{{lookup('env','PWD')}}/group_files/{{group_files_group}}/{{role_name}}/kiosk.tar.bz2"
    - "{{lookup('env','PWD')}}/group_files/all/{{role_name}}/kiosk.tar.bz2"
    - "default/kiosk.tar.bz2"
  register: copy


- name: delete kiosk-skel-dir
  file:
    path: "/etc/kiosk"
    state: absent
  when: copy.changed


- name: set up new kiosk-skel-dir
  file:
    path: "/etc/kiosk"
    state: directory
    mode: 0700
    owner: "kiosk"
    group: "kiosk"
  when: copy.changed


- name: extract kiosk-skel-dir
  unarchive:
    src: "/etc/kiosk.tar.bz2"
    dest: "/etc/kiosk"
    remote_src: yes
    mode: "u=rwX,g=rX,o-rwx"
    owner: "kiosk"
    group: "kiosk"
    extra_opts:
      - '--strip-components=1'
      - '--show-stored-names'
  when: copy.changed


- name: set up persistent kiosk storage
  file:
    path: "/var/kiosk"
    state: directory
    mode: 0775
    owner: "kiosk"
    group: "kiosk"

#TODO: deny crontab + at
