How can I escape characters in Ansible's lineinfile module?
Here's the line I want to insert on the server:
EMAIL='[email protected]' # Server notification email address enter only 1 address
But when I try the following, Ansible refuses to parse it due to YAML errors:
line="EMAIL='{{ email_address }}' # Server notification email address enter only 1 address"
I'm guessing it's because I have a strange combination of double quotes, single quotes, equal character and pound character.
The problem indeed is the #
in your string - for whatever reason.
Though you can easily prevent the parsing error by using this trick:
line="EMAIL='{{ email_address }}' {{ '#' }} Server notification email address enter only 1 address"
For longer form comments or for readability you could also add comments as vars:
.
name: Do something
vars:
comment: '# Server notification email address enter only 1 address'
lineinfile:
...
line="EMAIL='{{ email_address }}' {{ comment }}"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With