From the course: Ansible: From Basics to Guru by Pearson

Unlock this course with a free trial

Join today to access over 25,200 courses taught by industry experts.

Using when to run tasks in specific situations

Using when to run tasks in specific situations - Ansible Tutorial

From the course: Ansible: From Basics to Guru by Pearson

Using when to run tasks in specific situations

The next conditional is WHEN, WHEN is what you use to run tasks in specific situations. So WHEN statements are used to run a task conditionally. And it can be used to run a task only if specific conditions are true. That's useful if you need a certain amount of disk space to be available, a certain amount of memory to be available on a host, and more like that. variables but also registered variables and facts can be used to check conditions in WHEN statements. For instance, you can check if a task has run successfully, memory is available, a file exists and anything you can imagine. When using WHEN it is important to address the right variable type. That's because of the way how you write your WHEN statement. Here we have a couple of them. We have Ansible machine is x86-64 between double quotes. That is checking if the variable is a string, or better, if the variable value is a string. And the string is set to x86-64. Ansible distribution version is 8. That might be a surprising one,…

Contents