<!-- mobian-agent-page publisher="dailydev" canonical="https://daily.dev/posts/multiline-expressions-in-ansible-playbooks-ipspace-net-blog-ark2dl59f" -->

---
title: Multiline Expressions in Ansible Playbooks « ipSpace.net...
description: Using multiline YAML format (the `>` block scalar) in Ansible expressions can cause subtle bugs depending on the Ansible version. In older Ansible core...
canonical: https://daily.dev/posts/multiline-expressions-in-ansible-playbooks-ipspace-net-blog-ark2dl59f
twitter:card: summary_large_image
twitter:site: @dailydotdev
og:type: website
og:site_name: daily.dev
og:title: Multiline Expressions in Ansible Playbooks « ipSpace.net blog | daily.dev
og:description: Using multiline YAML format (the `>` block scalar) in Ansible expressions can cause subtle bugs depending on the Ansible version. In older Ansible core...
og:url: https://daily.dev/posts/multiline-expressions-in-ansible-playbooks-ipspace-net-blog-ark2dl59f
og:image: https://api.daily.dev/og/posts/ARK2DL59F.png
og:image:alt: Multiline Expressions in Ansible Playbooks « ipSpace.net blog
og:image:width: 1200
og:image:height: 630
og:locale: en
---

> ## Documentation Index
> Fetch the complete documentation index at: https://daily.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Multiline Expressions in Ansible Playbooks « ipSpace.net blog

**[ipSpace.net Blog](https://daily.dev/sources/ipspace)** · 2 min read · 0 upvotes · 0 comments

## Summary

Using multiline YAML format (the `>` block scalar) in Ansible expressions can cause subtle bugs depending on the Ansible version. In older Ansible core releases like 2.12.10 (shipped with RHEL 9.0), a trailing newline causes Jinja2 expressions to be evaluated as strings rather than booleans, turning a `false` result into a truthy non-empty string. Two workarounds exist: wrap the expression in quotes, or use the YAML Block Chomping Indicator (`>-`) instead of `>` to strip the trailing newline.

## Full article

daily.dev links to this article rather than hosting it. Read it at the original source: <https://blog.ipspace.net/2024/03/ansible-multiline-expressions>

## Questions this post answers

### Why does my Ansible set_fact return a string 'False\n' instead of boolean false when using a multiline Jinja2 expression?

A trailing newline added by YAML's `>` block scalar causes older Ansible core versions (e.g., 2.12.10 on RHEL 9.0) to evaluate the expression as a string rather than a boolean. A non-empty string is truthy, so `false` becomes `'False\n'`. Fix it by using `>-` (block chomping indicator) to strip the trailing newline, or by wrapping the expression in quotes.

_Developers debugging Ansible version-specific quirks like this track similar gotchas on daily.dev._

### How do I write a multiline Jinja2 expression in an Ansible playbook without breaking boolean evaluation?

Use the YAML Block Chomping Indicator `>-` instead of `>` when defining multiline expressions in Ansible. The `>-` strips the trailing newline that `>` appends, preventing Ansible from treating the result as a string. Alternatively, enclose the entire Jinja2 expression in double quotes across multiple lines to achieve the same effect.

_Teams maintaining Ansible playbooks across multiple core versions find version-specific pitfalls like this on daily.dev._

## Similar posts on daily.dev

- [How to collaborate with AI to improve your Ansible skills](https://daily.dev/posts/how-to-collaborate-with-ai-to-improve-your-ansible-skills-izxeypqlm) · Red Hat Developer · 0 upvotes · 0 comments
- [The Crappy Cisco IOS CLI Error Reporting « ipSpace.net blog](https://daily.dev/posts/the-crappy-cisco-ios-cli-error-reporting-ipspace-net-blog-2cshblas0) · ipSpace.net Blog · 0 upvotes · 0 comments
- [YAML? That’s Norway problem](https://daily.dev/posts/yaml-that-s-norway-problem-jgyckvk2a) · Programming Digest · 4 upvotes · 0 comments
- [Ansible Security Automation: Risks & 7 Best Practices](https://daily.dev/posts/ansible-security-automation-risks-7-best-practices-lvgbynirc) · Spacelift · 2 upvotes · 0 comments

---

Tags: [#ansible](https://daily.dev/tags/ansible)

[View this post on daily.dev](https://daily.dev/posts/multiline-expressions-in-ansible-playbooks-ipspace-net-blog-ark2dl59f)

```json
{"@context":"https://schema.org","@graph":[{"@type":"Organization","@id":"https://daily.dev/#organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180},"sameAs":["https://twitter.com/dailydotdev","https://github.com/dailydotdev","https://www.linkedin.com/company/daily-dev-ltd"]},{"@type":"WebSite","@id":"https://daily.dev/#website","url":"https://daily.dev","name":"daily.dev","publisher":{"@id":"https://daily.dev/#organization"},"potentialAction":{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https://daily.dev/search?q={search_term_string}"},"query-input":"required name=search_term_string"}}]}
{"@context":"https://schema.org","@type":"TechArticle","headline":"Multiline Expressions in Ansible Playbooks « ipSpace.net blog","url":"https://daily.dev/posts/multiline-expressions-in-ansible-playbooks-ipspace-net-blog-ark2dl59f","mainEntityOfPage":{"@type":"WebPage","@id":"https://daily.dev/posts/multiline-expressions-in-ansible-playbooks-ipspace-net-blog-ark2dl59f"},"datePublished":"2026-08-11T08:54:40.536Z","dateModified":"2026-08-24T07:07:26.604Z","description":"Using multiline YAML format (the `>` block scalar) in Ansible expressions can cause subtle bugs depending on the Ansible version. In older Ansible core...","image":"https://media.daily.dev/image/upload/s--CxzD6vbw--/f_auto/v1722860399/public/Placeholder%2005","thumbnailUrl":"https://media.daily.dev/image/upload/s--CxzD6vbw--/f_auto/v1722860399/public/Placeholder%2005","isAccessibleForFree":true,"articleSection":"ipSpace.net Blog","inLanguage":"en","publisher":{"@type":"Organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180}},"author":{"@type":"Organization","name":"ipSpace.net Blog","logo":"https://media.daily.dev/image/upload/s--xS7E82MT--/f_auto,q_auto/v1786438303/logos/ipspace?_a=BAMAMicg0","url":"https://daily.dev/sources/ipspace"},"commentCount":0,"discussionUrl":"https://daily.dev/posts/multiline-expressions-in-ansible-playbooks-ipspace-net-blog-ark2dl59f","interactionStatistic":[{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":0},{"@type":"InteractionCounter","interactionType":{"@type":"CommentAction"},"userInteractionCount":0}],"keywords":"ansible","timeRequired":"PT2M"}
{"@context":"https://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https://daily.dev"},{"@type":"ListItem","position":2,"name":"ipSpace.net Blog","item":"https://daily.dev/sources/ipspace"},{"@type":"ListItem","position":3,"name":"Multiline Expressions in Ansible Playbooks « ipSpace.net blog"}]}
{"@context":"https://schema.org","@type":"FAQPage","@id":"https://daily.dev/posts/multiline-expressions-in-ansible-playbooks-ipspace-net-blog-ark2dl59f#faq","mainEntity":[{"@type":"Question","name":"Why does my Ansible set_fact return a string 'False\\n' instead of boolean false when using a multiline Jinja2 expression?","acceptedAnswer":{"@type":"Answer","text":"A trailing newline added by YAML's `>` block scalar causes older Ansible core versions (e.g., 2.12.10 on RHEL 9.0) to evaluate the expression as a string rather than a boolean. A non-empty string is truthy, so `false` becomes `'False\\n'`. Fix it by using `>-` (block chomping indicator) to strip the trailing newline, or by wrapping the expression in quotes. Developers debugging Ansible version-specific quirks like this track similar gotchas on daily.dev."}},{"@type":"Question","name":"How do I write a multiline Jinja2 expression in an Ansible playbook without breaking boolean evaluation?","acceptedAnswer":{"@type":"Answer","text":"Use the YAML Block Chomping Indicator `>-` instead of `>` when defining multiline expressions in Ansible. The `>-` strips the trailing newline that `>` appends, preventing Ansible from treating the result as a string. Alternatively, enclose the entire Jinja2 expression in double quotes across multiple lines to achieve the same effect. Teams maintaining Ansible playbooks across multiple core versions find version-specific pitfalls like this on daily.dev."}}]}
```

