#SPDX-License-Identifier: MIT-0
---
# tasks to setup debian hosts

- name: Update package cache (Debian/Ubuntu)
  apt:
    update_cache: yes
  when: ansible_facts['os_family'] == "Debian"

- name: Upgrade all packages (Debian/Ubuntu)
  apt:
    upgrade: dist
  register: debian_update
  when: ansible_facts['os_family'] == "Debian"

# Setup unattended-upgrade
- name: install packages (Debian)
  apt:
    name: [ unattended-upgrades, apt-listchanges, cron ]
    update_cache: yes
    state: present
  when: ansible_facts['os_family'] == 'Debian'
  tags:
    - packages

- name: template unattended-upgrades config (Debian)
  template:
    src: 50unattended-upgrades
    dest: /etc/apt/apt.conf.d/50unattended-upgrades
    owner: root
    group: root
    mode: 0644
  when: ansible_facts['os_family'] == 'Debian'
  tags:
    - unattended

- name: restart unattended-upgrades service (Debian)
  service:
    name: unattended-upgrades
    state: restarted
  when: ansible_facts['os_family'] == 'Debian'
  tags:
    - unattended

- name: Setup Cronjob for unattended-upgrade
  ansible.builtin.cron:
    name: "Auto-Update"
    minute: "30"
    hour: "2"
    job: "/usr/bin/unattended-upgrade"
  when: ansible_facts['os_family'] == 'Debian'

# Setup fastfetch prompt
- name: Create fastfetch directory
  ansible.builtin.file:
    path: /etc/fastfetch
    state: directory
    owner: root
    group: root
    mode: '0744'

- name: Copy fastfetch config
  ansible.builtin.copy:
    src: 27.jsonc
    dest: /etc/fastfetch/27.jsonc
    owner: root
    group: root
    mode: '0744'

- name: Copy fastfetch script
  ansible.builtin.copy:
    src: fastfetch-motd.sh
    dest: /etc/profile.d/fastfetch-motd
    owner: root
    group: root
    mode: '0644'


