All three ways you wrote are valid in Ansible, but there are subtle differences in syntax and formatting:
1️⃣ Single-line without quotes
-
Works fine for simple single-line messages.
-
No quotes needed if there are no special characters.
-
Best for short messages.
2️⃣ Single-line with quotes
-
Also works the same as above.
-
Quotes allow using special characters (like
:) or spaces at the start/end safely. -
Good practice if your message might include special YAML characters.
3️⃣ Multi-line / folded style (>)
-
>allows multi-line YAML strings. -
Line breaks in YAML become spaces in the final string.
-
Useful if your message spans multiple lines.
Example:
-
This produces a single line in output:
"Successfully connected to postgres on oel02db.mydb.com. Database size: 12345"
✅ Summary / Recommendation
| Style | Use case |
|---|---|
| No quotes | Simple, short messages |
| Quotes | Messages with special characters or punctuation |
> folded | Long messages, multiple lines, better readability |
No comments:
Post a Comment