Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Undefined variable when running Ansible play

I am running multiple ansible plays defined in YAML files.

In the last play I get the following error:

{"failed": true, "msg": "The conditional check 'ansible_os_family == \"RedHat\"' failed. The error was: error while evaluating conditional (ansible_os_family == \"RedHat\"): 'ansible_os_family' is undefined\n

Do I need to change anything with the facts gathering or something in the ansible.cfg?

like image 573
Souciance Eqdam Rashti Avatar asked Jan 12 '17 15:01

Souciance Eqdam Rashti


People also ask

How do you know if a variable is defined or not in Ansible?

As per latest Ansible Version 2.5, to check if a variable is defined and depending upon this if you want to run any task, use undefined keyword. Show activity on this post. Strictly stated you must check all of the following: defined, not empty AND not None.

What does Set_fact do in Ansible?

This module allows setting new variables. Variables are set on a host-by-host basis just like facts discovered by the setup module. These variables will be available to subsequent plays during an ansible-playbook run.


1 Answers

Add:

gather_facts: true

to your last play and try.

like image 127
helloV Avatar answered Oct 17 '22 00:10

helloV