Scenario / Questions

Using ansible 1.5.4, the command

lineinfile: dest=/etc/bash.bashrc line="bind '\"\e[B\"':history-search-forward"

added the line

bind '"\e[B"':history-search-forward

to /etc/bash.bashrc perfectly fine.

On ansible 1.9.1, the same ansible instruction produces the following line, which messes the quotes I escaped in the lineinfile command:

bind \e[B:history-search-forward

How can I fix the quotes, so that the correct line is added

Find below all possible solutions or suggestions for the above questions..

Suggestion: 1

You can usually avoid some of escaping mess by using the multiline form of input, especially when entering colons:

command: >
curl -X POST -H 'Content-Type: application/json' --data '{"name": "{{ }}", "comment": "{{ item.comment }}", "DefaultDistribution": "{{ item.default_distribution }}", "DefaultComponent": "{{ item.default_component }}" }' http://localhost:8080/api/repos

Suggestion: 2

I wrote a little Ansible playbook that I think does what you want (although to a test file instead of the actual bashrc.


- name: Example for
  hosts: all
  - name: Put line with quotes, backslash, and colon in a file
      dest: /home/vagrant/testfile.txt
      create: yes
      line: "bind '\"\\e[B\"':history-search-forward"

I have run this and I get this line in testfile.txt:

bind '"\e[B"':history-search-forward

I am using Ansible I don’t know if that differs from 1.9.1