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
私はAnsible 2.1.1.0を使用しています。1.9.1と異なるかどうかはわかりません。