Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.Sign up
String with backslash at the end #10464
I have a file with the following content:
In my playbook I have the following task:
When I execute Ansible it says
I tried two backslashes
I tried to insert a space between the backslash and the quotation mark, but then the final shell file is invalid (because the backslash escapes the space character and not the line break).
Is this a bug or am I doing something wrong?
Hi @michel-kraemer, I've been looking into this and there is a way to get around the parsing error, which involves using the dictionary syntax for arguments:
- lineinfile: dest: "/tmp/test_10464.txt" line: " -Dlog4j.configuration=file:$VERTX_HOME/conf/log4j.properties -Dorg.vertx.logger-delegate-factory-class-name=org.vertx.java.core.logging.impl.Log4jLogDelegateFactory \\" regexp: "-Djava\\.util\\.logging\\.config\\.file"
Note the double
The original issue arises from our key="value" parser thinking that you're escaping that quote, since we do not ourselves check for a double
referenced this issue
Nov 3, 2016
There's a variety of workarounds for this including the ones posted in comments above and using the extra space at the end but running it through jinja2's trim filter:
However, the supported way to do this in Ansible-2.x is to use yaml dicts:
k=v parsing has cornercases like this that will always make it inferior to yaml dicts when there is a need for escaping or complex quoting.
Since yaml dict format works and there are several workarounds if someone feels they must use k=v I'll close this ticket.