How to nicely split on multiple lines long conditionals with OR on ansible?

Use the YAML folding operator >

when: >
  ansible_user_dir is not defined or
  ansible_python is not defined or
  ansible_processor_vcpus is not defined

As the ansible documentation states:

Values can span multiple lines using | or >. Spanning multiple lines using a Literal Block Scalar | will include the newlines and any trailing spaces. Using a Folded Block Scalar > will fold newlines to spaces; it’s used to make what would otherwise be a very long line easier to read and edit. In either case the indentation will be ignored.

Additional info can be found here:

  • https://yaml-multiline.info/
  • https://docs.ansible.com/ansible/latest/reference_appendices/YAMLSyntax.html
  • http://yaml.org/spec/1.2/spec.html#id2760844

Leave a Comment