---
- name: Include variables based on the operating system
  include_vars: "{{ ansible_os_family }}.yml"

- name: "Find the latest version of {{ app_name }} from the release page"
  uri:
    url: https://releases.hashicorp.com/consul-template/
    return_content: true
  register: consultemplate_version
  when: ansible_os_family != 'Windows'

- name: "Save the version of {{ app_name }} to a variable"
  set_fact:
    consultemplate_version: "{{ consultemplate_version.content | regex_search('_(((\\d)*\\.)*\\d*)') | replace ('_','') }}"
  when: ansible_os_family != 'Windows'

# @action Ensures consul-template is installed
# Installs consul-template on Archlinux, CentOS, Debian, Fedora, macOS, Ubuntu, and Windows
# @action Ensures consul-template is installed
# Ensure consul-template binary is available in PATH
- name: Include tasks based on the operating system
  become: true
  become_method: "{{ 'runas' if ansible_os_family == 'Windows' else 'sudo' }}"
  become_user: "{{ ansible_user if ansible_os_family == 'Windows' else omit }}"
  block:
    - include_tasks: "install-{{ ansible_os_family }}.yml"
