ansible中带LINEINFLE的换行符

ansible中带LINEINFLE的换行符,ansible,Ansible,我发现尊重正则表达式换行符\n的唯一方法是在一行中用双引号连接所有内容 --- - name: Custom prompt output lineinfile: path: ~/.zshrc line: "\n# Custom Prompt\nlocal user=\"%{$fg[yellow]%}%n%{$fg[white]%}@%{$fg[green]%}%m%{$reset_color%}\"\nPROMPT=\"${user} ${PROMPT}\"" sta

我发现尊重正则表达式换行符
\n
的唯一方法是在一行中用双引号连接所有内容

---
- name: Custom prompt output
  lineinfile:
    path: ~/.zshrc
    line: "\n# Custom Prompt\nlocal user=\"%{$fg[yellow]%}%n%{$fg[white]%}@%{$fg[green]%}%m%{$reset_color%}\"\nPROMPT=\"${user} ${PROMPT}\""
    state: present

结果如我所料是正确的,但太难看了。有没有更好的方法?

一个选择是使用

-名称:自定义提示输出
区块填充:
路径:~/.zshrc
创建:是
区块:|
#自定义提示
本地用户=“%{$fg[黄色]]}%n%{$fg[白色]]}@%{$fg[绿色]]]}%m%{$reset\u color%}”
PROMPT=“${user}${PROMPT}”