# Copyright (c) Ontic. (http://www.ontic.com.au). All rights reserved.
# See the COPYING file bundled with this package for license details.

---

- name: 'Fonts | Debian | Install HTTPS transport.'
  become: yes
  apt:
    name: 'apt-transport-https'
    state: 'latest'
  when: 'ansible_os_family == "Debian"'

- name: 'Fonts | Debian | Update repository list.'
  become: yes
  apt_repository:
    repo: '{{ item }}'
    state: 'present'
    update_cache: false
  register: 'fonts_multiverse_installed'
  notify: 'rebuild fonts cache'
  with_items: '{{ fonts_repositories }}'
  when: 'ansible_distribution == "Debian"'

- name: 'Fonts | Debian | Update APT cache.'
  become: yes
  apt:
    update_cache: yes
  when: 'ansible_os_family == "Debian" and fonts_multiverse_installed.changed'

- name: 'Fonts | Debian | Install Microsoft Core Fonts prerequisites.'
  become: yes
  apt:
    name: '{{ item }}'
    state: 'present'
  with_items:
    - 'libfreetype6'
    - 'libfreetype6-dev'
    - 'fontconfig'
  when: 'ansible_os_family == "Debian"'

- name: 'Fonts | Debian | Accept Microsoft Core Fonts EULA.'
  become: yes
  debconf:
    name: 'ttf-mscorefonts-installer'
    question: 'msttcorefonts/accepted-mscorefonts-eula'
    value: 'true'
    vtype: 'select'
  when: 'ansible_os_family == "Debian"'

- name: 'Fonts | Debian | Install Microsoft Core Fonts.'
  become: yes
  apt:
    name: 'ttf-mscorefonts-installer'
    state: 'present'
  register: 'fonts_microsoft_installed'
  notify: 'rebuild fonts cache'
  when: 'ansible_os_family == "Debian"'

- name: 'Fonts | RedHat | Install Microsoft Core Fonts prerequisites.'
  become: yes
  yum:
    name: '{{ item }}'
    state: 'present'
  with_items:
    - 'curl'
    - 'cabextract'
    - 'xorg-x11-font-utils'
    - 'fontconfig'
  when: 'ansible_os_family == "RedHat"'

- name: 'Fonts | RedHat | Install Microsoft Core Fonts.'
  become: yes
  yum:
    name: 'https://raw.githubusercontent.com/therevoman/mscorefonts2-code/master/RPMS/noarch/msttcore-fonts-installer-2.6-1.noarch.rpm'
    state: 'present'
    validate_certs: no
  notify: 'rebuild fonts cache'
  when: 'ansible_os_family == "RedHat"'