Ansible When Fact Equals

Here ansible_os_family is the fact variable. If this variable value equals to Redhat then this task will be executed
otherwise this task will be skipped.

Ansible When Fact Exists

Here the first task will be executed only when foo variable is defined. If the foo variable is not defined then first task will be skipped. If the bar variable is not defined Second task will fail with by displaying that message. If bar variable is defined second task will be skipped.

Ansible when Fact is True And Ansible when Fact is False

Here we defined one variable called jboss_run as true. So the first task will be executed since we defined when condition as if jboss_run is true execute script. This condition is true so the first task will be executed. Second task will be skipped since the condition is false.


when: jboss_run means         jboss_run variable value is true

when: not jboss_run means  jboss_run variable value is false


  • ansible when fact exists
  • ansible when fact is true
  • ansible when fact contains
  • ansible when fact equals
  • ansible when fact is false