ansible lineinfile 이스케이프된 따옴표가 누락되었습니다.

ansible lineinfile 이스케이프된 따옴표가 누락되었습니다.

ansible 1.5.4를 사용하여 명령

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

라인을 추가했습니다

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

완벽 하게 /etc/bash.bashrc괜찮습니다.

Ansible 1.9.1에서 동일한 Ansible 명령어는 다음 줄을 생성하는데, 이는 lineinfile 명령에서 이스케이프한 따옴표를 엉망으로 만듭니다.

bind \e[B:history-search-forward

올바른 줄이 추가되도록 따옴표를 어떻게 수정합니까?

답변1

특히 콜론을 입력할 때 여러 줄 형식의 입력을 사용하면 일반적으로 혼란을 피할 수 있습니다.

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

답변2

나는 당신이 원하는 것을 수행한다고 생각하는 작은 Ansible 플레이북을 작성했습니다(실제 bashrc 대신 테스트 파일을 사용했지만).

---

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

이것을 실행했는데 testfile.txt에 다음 줄이 표시됩니다.

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

저는 앤서블 2.1.1.0을 사용하고 있습니다. 1.9.1과 다른지는 모르겠습니다.

관련 정보