---
- name: Update apt cache
  ansible.builtin.apt:
    update_cache: true
  become: true

- name: Upgrade installed packages
  ansible.builtin.apt:
    upgrade: dist
  become: true

- name: Install base packages
  ansible.builtin.apt:
    name: "{{ signage_base_packages }}"
    state: present
  become: true

- name: Set system timezone
  community.general.timezone:
    name: "{{ signage_timezone }}"
  become: true

- name: Disable systemd-timesyncd if present (chrony replaces it)
  ansible.builtin.systemd:
    name: systemd-timesyncd
    enabled: false
    state: stopped
  become: true
  failed_when: false

- name: Ensure chrony NTP service is enabled and running
  ansible.builtin.systemd:
    name: chrony
    enabled: true
    state: started
  become: true

- name: Ensure journald drop-in directory exists
  ansible.builtin.file:
    path: /etc/systemd/journald.conf.d
    state: directory
    owner: root
    group: root
    mode: "0755"
  become: true

- name: Configure journald volatile storage (RAM only, schont SD-Karte)
  ansible.builtin.copy:
    dest: /etc/systemd/journald.conf.d/morz-volatile.conf
    content: |
      [Journal]
      Storage=volatile
      RuntimeMaxUse=20M
    owner: root
    group: root
    mode: "0644"
  become: true
  notify: Restart journald

- name: Ensure signage user exists
  ansible.builtin.user:
    name: "{{ signage_user }}"
    create_home: true
    state: present
  become: true
