O'Reilly logo

Ansible Configuration Management - Second Edition by Daniel Hall

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Conditional execution

Some modules, such as the copy module, provide mechanisms to configure it to skip the execution of the module. You can also configure your own skip conditions that will only execute the module if they resolve to true. This can be handy if your servers use different packaging systems or have different filesystem layouts. It can also be used with the set_fact module to allow you to compute many different things.

To skip a module, you can use the when key; this lets you provide a condition. If the condition you set resolves to false, then the module will be skipped. The value that you assign to when is a Python expression. You can use any of the variables or facts available to you at this point.

Note

If you want to process some ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required