Table of Contents

About

When downloading executable binary, you need to detect the type of OS. This script will show you how to do it in ansible with facts

Script

- name: Set OS variable for Linux
  set_fact:
    host_os: "linux"
  when: ansible_facts['os_family'] == "Debian" or ansible_facts['os_family'] == "RedHat" or ansible_facts['os_family'] == "Suse"

- name: Set OS variable for macOS
  set_fact:
    host_os: "macos"
  when: ansible_facts['os_family'] == "Darwin"

- name: Set OS variable for Windows
  set_fact:
    host_os: "windows"
  when: ansible_facts['os_family'] == "Windows"