---
# file: oracle-java/tasks/main.yml
#
# tasks file
#

- name: check host environment
  include: check_environment.yml

## include OS family specific variables

- name: include OS family/distribution specific variables
  include_vars: "{{ item }}"
  with_first_found:
    - "defaults/{{ ansible_os_family | lower }}-{{ ansible_distribution | lower }}.yml"
    - "defaults/{{ ansible_os_family | lower }}.yml"
  tags: installation

- include: debug.yml
  when: debug | default(false)
  tags: debug

- name: check if operating system is suported
  fail:
    msg: "The operating system ({{ ansible_os_family }}) of the target machine ({{ inventory_hostname }}) is not currently supported."
  when: oracle_java_os_supported is not defined or not oracle_java_os_supported

## include OS family specific task file

- name: if darwin/macosx, include distribution specific task file
  include: "darwin/macosx.yml"
  when: ansible_os_family | lower == 'darwin' and ansible_distribution | lower == 'macosx'

- name: if debian, include family specific task file
  include: "debian/main.yml"
  when: ansible_os_family | lower == 'debian'

- name: if redhat, include family specific task file
  include: "redhat/main.yml"
  when: ansible_os_family | lower == 'redhat'

---
# file: oracle-java/tasks/main.yml
#
# tasks file
#

- name: check host environment
  include: check_environment.yml

## include OS family specific variables

- name: include OS family/distribution specific variables
  include_vars: "{{ item }}"
  with_first_found:
    - "{{ role_path }}/defaults/{{ ansible_os_family | lower }}-{{ ansible_distribution | lower }}.yml"
    - "{{ role_path }}/defaults/{{ ansible_os_family | lower }}.yml"
  tags: installation

- include: debug.yml
  when: debug | default(false)
  tags: debug

- name: check if operating system is suported
  fail:
    msg: "The operating system ({{ ansible_os_family }}) of the target machine ({{ inventory_hostname }}) is not currently supported."
  when: oracle_java_os_supported is not defined or not oracle_java_os_supported

## include OS family specific task file

- name: if darwin/macosx, include distribution specific task file
  include: "darwin/macosx.yml"
  when: ansible_os_family | lower == 'darwin' and ansible_distribution | lower == 'macosx'

- name: if debian, include family specific task file
  include: "debian/main.yml"
  when: ansible_os_family | lower == 'debian'

- name: if redhat, include family specific task file
  include: "redhat/main.yml"
  when: ansible_os_family | lower == 'redhat'

Resolve file path with `{{ role_path }}`
Resolve file path with `{{ role_path }}`

I was getting errors with this playbook when executing "include OS
family/distribution specific variables." Even though my
`ansible_os_family` is `RedHat`, `with_first_found` was finding no
results. (I am running Centos 7, but I confirmed the `RedHat` value
in the ansible facts with `ansible all -m setup`.)

When I prepended the `defaults/...` relative path with `{{ role_path
}}`, this playbook ran successfully.
