# SSH
- name: install ssh
  pacman:
    name:
      - openssh

- name: enable and start ssh service
  systemd:
    name: sshd
    enabled: yes
    state: started

# PLOCATE
- name: install plocate
  pacman:
    name:
      - plocate

- name: enable and start ~12h updatedb timer
  systemd:
    name: plocate-updatedb.timer
    enabled: yes
    state: started

# ARCH KEYRING WEEKLY UPDATE
- name: archlinux-keyring - enable weekly update
  systemd:
    name: archlinux-keyring-wkd-sync.timer
    enabled: yes
    state: started

# SDD TRIM
- name: install util-linux
  pacman:
    name:
      - util-linux

- name: enable and start weekly ssd disks trim using fstrim timer
  systemd:
    name: fstrim.timer
    enabled: yes
    state: started

# REFLECTOR
- name: install reflector
  pacman:
    name:
      - reflector

- name: write reflector configuration file
  copy:
    dest: "/etc/xdg/reflector/reflector.conf"
    content: |
      --save /etc/pacman.d/mirrorlist
      --protocol http
      --country Spain
      --country France
      --country Germany
      --country Portugal
      --country Italy
      --country United_Kingdom
      --latest 20
      --score 20
      --sort rate

- name: enable and start reflector timer
  systemd:
    name: reflector.timer
    enabled: yes
    state: started

- name: do initial run of reflector.service
  systemd:
    name: reflector
    enabled: yes
    state: started

# LOGROTATE
- name: install logrotate
  pacman:
    name:
      - logrotate

- name: logrotate - enable compression
  lineinfile:
    path: /etc/logrotate.conf
    regexp: "^#compress$"
    line: "compress"

- name: enable and start daily logs rotation, cleanup
  systemd:
    name: logrotate.timer
    enabled: yes
    state: started

# DOCKER
- name: install docker and docker compose
  pacman:
    update_cache: yes
    name:
      - docker
      - docker-compose

- name: install lazydocker
  kewlfft.aur.aur:
    name:
      - lazydocker

- name: docker service
  systemd:
    name: docker
    enabled: yes
    state: restarted

- name: add the user to docker group
  user:
    name: "{{ ansible_user }}"
    groups: docker
    append: yes

- name: Create /etc/docker directory if it does not exist
  file:
    path: /etc/docker
    state: directory
    mode: "0755"

- name: set default max logs size to 250MB and set logs rotation
  copy:
    dest: "/etc/docker/daemon.json"
    content: |
      {
        "log-driver": "json-file",
        "log-opts": {
          "max-size": "50m",
          "max-file": "5"
        }
      }

# PIPEWIRE
- name: install pipewire and dependencies
  pacman:
    name:
      - pipewire
      - pipewire-alsa
      - wireplumber
      - alsa-utils

- name: Pipewire service
  systemd:
    name: pipewire
    state: restarted
    enabled: yes

- name: WirePlumber service
  systemd:
    name: wireplumber
    state: restarted
    enabled: yes
