I’m writing an Ansible role that is supposed to run on Debian and RedHat.
In my module, the default values for Red Hat and Debian are different, so I thought I could just create Debian.yml and RedHat.yml in the default folder, but this did not work out of the box.
Where can I set the appropriate values so this works just like for vars?
I tried it in the same way with:
- name: Include distribution specific variables
include_vars: "{{ ansible_os_family }}.yml"
tags: module
2
Answers
By default, the
main.yml
files are loaded automatically, filesDebian.yml
andRedHat.yml
indefaults
directory aren’t loaded automatically. You could load them with task"Include distribution specific variable"
that you wrote, this task must be the first task inmain.yml
file in your role as belowUnfortunately Ansible doesn’t let you include defaults.
What you can do tho, is include vars like this:
then override included vars when needed, with: