Best way to define variables based on facts for a role

Hi,

I’m trying to write a role that has different template file if the server is virtual os physical.
What’s the best way to filter this?

Thanks,
Bruno

I use these ansible facts for differentiating between physical and virtual guests:

“ansible_virtualization_role”: “guest”,
“ansible_virtualization_type”: “kvm”,

These work perfect along with a ‘when’ conditional. For example:

  • template:
    src:
    dest:
    when: ansible_virtualization_role is defined or ansible_virtualization_role == “kvm”

If you want to explore more variables, run the following adhoc command on both the physical and virtual hosts and notice the change is the value of variables that facts report:

ansible all -m setup | less

-R.Rao

Hi R.Rao,

Thanks, gonna try that

Bruno