Conditional checks use the when:
syntax. When conditions can use raw Jinja2 expressions (regex) but can execute regular python code so can access methods like String.find() to check for a text match in a String. Multiple conditions should be enclosed with parenthesis, multiple conditions can be specified in a list where they are all required to be true (logical AND).
Example
when: - tomcat_status_result.stdout.find("JVM is running.") > -1 - tomcat_status_result.stderr != "" - tomcat_status_result.rc == 0 --- - hosts: all tasks: - name: "print inventory vars" debug: var: "{{ item }}" with_items: - inventory_dir - inventory_file when: inventory_dir | regex_search('dev$') - hosts: all tasks: - name: "apply stub role" include_role: name: issuer-wallet-stub when: inventory_dir | regex_search('dev$')