- name: Put in custom config directory
  copy:
    src: "files/pacman.conf"
    dest: /etc/pacman.conf
    mode: 0644
    owner: root
    group: root

- name: Put in mirrolist
  copy:
    src: "files/mirrorlist"
    dest: /etc/pacman.d/mirrorlist
    mode: 0644
    owner: root
    group: root

- name: Create pacman conf directory
  file:
    name: /etc/pacman.d/conf.d
    state: directory
    owner: root
    group: root
    mode: 0755

- name: Check that paths exist
  stat:
    path: "{{ item }}"
  register: file_exists
  no_log: True
  loop:
    - /etc/pacman.d/conf.d/blank.conf

- name: Create blank file to match glob
  file:
    name: "{{ item }}"
    state: touch
    owner: root
    group: root
    mode: 0644
  loop:
    - /etc/pacman.d/conf.d/blank.conf
  when: "{{ file_exists | community.general.json_query(sub_query) | first | default(False) }} == False"
  vars:
    sub_query: "results[?stat.path=='{{ item }}'].stat.exists"

- name: Additional pacman configs
  copy:
    src: "files/{{ item }}"
    dest: /etc/pacman.d/conf.d/
    mode: 0644
    owner: root
    group: root
  loop:
    - freeze_firefox.conf