ansible 1.9.4 ignoring escaped double quotes with lineinfile?

258 views
Skip to first unread message

Joel Parker

unread,
Jan 11, 2016, 1:45:16 AM1/11/16
to Ansible Project
I know this has been a bug in the recent past, but I'm running into this with Ansible 1.9.4 on FreeBSD.

 - name: update loader.conf
    lineinfile: dest={{ item.dest }} regexp={{ item.regexp }} line={{ item.line}} state={{ item.state }} backup={{ item.backup }} create={{ item.create }}
    with_items:
      - { dest: "/boot/loader.conf", regexp: "^vmm_load", line: "vmm_load=\"YES\"", state: "present", backup: "no", create: "yes" }
 

Obviously I'm wanting the result to be:
vmm_load="YES"

However the actual result is:
vmm_load=YES


I do see that the following *does* work as expected (note removed quotes):
 - name: update loader.conf
    lineinfile: dest={{ item.dest }} regexp={{ item.regexp }} line={{ item.line}} state={{ item.state }} backup={{ item.backup }} create={{ item.create }}
    with_items:
      - { dest: "/boot/loader.conf", regexp: "^vmm_load", line: vmm_load=\"YES\", state: "present", backup: "no", create: "yes" }


Am I incorrectly placing double quotes around everything in my dict, or is ansible failing to handle yaml like it should?

Joel Parker

unread,
Jan 12, 2016, 3:51:42 PM1/12/16
to Ansible Project
Any thoughts?

Toshio Kuratomi

unread,
Jan 13, 2016, 12:38:39 PM1/13/16
to ansible...@googlegroups.com
In 1.9.4, you'll need to use
- { dest: "/boot/loader.conf", regexp: "^vmm_load", line:
vmm_load=\\\"YES\\\", state: "present", backup: "no", create: "yes" }

(three backslashes).

In 2.0 we fixed this so that \" will work correctly there.

Quoting and escaping is tricky inside of the ansible code because we
use yaml to parse the playbook and then jinja2 to substitute
variables. We try to abstract that away but sometimes it leaks out
and you end up having to escape for both of the parsers. Hopefully we
fixed most of those in 2.0.

-Toshio
> --
> You received this message because you are subscribed to the Google Groups
> "Ansible Project" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to ansible-proje...@googlegroups.com.
> To post to this group, send email to ansible...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/83d4be58-6cca-44b1-9bd1-5295920408d9%40googlegroups.com.
>
> For more options, visit https://groups.google.com/d/optout.

Joel Parker

unread,
Jan 13, 2016, 9:00:38 PM1/13/16
to Ansible Project
thank you for the explanation
Reply all
Reply to author
Forward
0 new messages