# Multiline Expressions in Ansible Playbooks

DevFeed: [Multiline Expressions in Ansible Playbooks](<https://devfeed.tech/articles/multiline-expressions-in-ansible-playbooks-10953.md>)

Original publisher: [Read original article](<https://blog.ipspace.net/2024/03/ansible-multiline-expressions/>)

Published: 2024-03-06T06:33:00Z

Content type: tutorial

Language: en

Sources: [ipSpace.net blog](<https://devfeed.tech/sources/ipspace-net-blog.md>)

Topics: [Ansible](<https://devfeed.tech/topics/ansible.md>), [YAML](<https://devfeed.tech/topics/yaml.md>)

Tags: [ansible](<https://devfeed.tech/tags/ansible.md>), [readability](<https://devfeed.tech/tags/readability.md>), [release](<https://devfeed.tech/tags/release.md>), [yaml](<https://devfeed.tech/tags/yaml.md>)

## AI overview

This tutorial explains that multiline YAML formatting can add a trailing newline to Ansible expressions. In older Ansible core releases, that newline may cause an expression to be evaluated as a non-empty string and therefore as true. It recommends avoiding multiline YAML formatting in Ansible expressions or removing the trailing newline with quotes or a YAML block chomping indicator.

## Source excerpt

Another week, another Ansible quirk 🤷♂ Imagine you have a long Jinja2 expression, and you want to wrap it into multiple lines to improve readability. Using multiline YAML format seems to be the ideal choice: --- - name: Test playbook hosts: localhost tasks: - set_fact: a: > {{ 123 == 345 or 123 > 345 }} It works every time 50% of the time (this time depending on your Ansible version). Read more ...