Ansible Determine Operating System

Solution 1:

ansible_distribution_release

The fact is called ansible_distribution_release. If you are running Ubuntu 14.04, the fact would read "trusty".

Two other example values: ansible_distribution_release would be "xenial" for Ubuntu 16.04 and "precise" for Ubuntu 12.04.

ansible_distribution_version

You can also look at the fact ansible_distribution_version. For Ubuntu 14.04, you would see "14.04".

Two other example values: ansible_distribution_version would be "16.04" for Ubuntu 16.04 and "12.04" for Ubuntu 12.04.

Here is an example task that you could put into a playbook to install the build-essential package only on Ubuntu 14.04:

- name: Install build-essential for Ubuntu 14.04 only
  apt: name=build-essential state=present
  when: ansible_distribution_version == "14.04"