While it is not possible to prevent the processing of a dependency role with a conditional, it is possible to skip all the tasks within a dependency role hierarchy by applying a conditional to a dependency. This mirrors the functionality of task inclusion with conditionals as well. The when key is used to express the conditional. Once again, we'll grow our example by adding a dependency to demonstrate the syntax:
--- dependencies: - role: common simple_var_a: True simple_var_b: False tags: common_demo - role: apache complex_var: key1: value1 key2: value2 short_list: - 8080 - 8081 tags: - apache_demo - 8080 - 8181 when: backend_server == 'apache'
In this example, the apache role will always be processed, but tasks within the role will only be run when the backend_server variable contains the apache string.