【问题标题】:ansible lineinfile module - combine quotes and double quotesansible lineinfile 模块 - 结合引号和双引号
【发布时间】:2015-07-29 19:15:30
【问题描述】:

我正在尝试添加包含单引号和双引号的行,但我已经筋疲力尽了一个小时...

vars:
  line1: "a=\\\"a'b'c\\\""
  line2: 'a="a\''b\''c"'
tasks:
- name: lineinfile test
  lineinfile: dest=/tmp/tmp line={{item}}
  with_items:
    - "{{line1}}"
    - "{{line2}}"

所需的行是a="a'b'c"

/tmp/tmp 的内容是

a="abc"
a=a'b'c

所以也没有诀窍..想法?

【问题讨论】:

  • line2: a=\\\"a\\\'b\\\'c\\\"(别问我为什么:)
  • @dusan.bajic 完美!!!请作为答案发布以供将来参考。
  • 使用 lineinfile 是一种反模式——在极少数情况下template 不能使用。
  • @tedder42 好吧,我正在使用它向现有的配置文件(如 bashrc、bash_aliases、fstab)添加行。据我所知,这是唯一的方法。如果我错过了什么,请点亮我的眼睛。谢谢。

标签: ansible


【解决方案1】:
line2: a=\\\"a\\\'b\\\'c\\\"

非常欢迎任何可以通过解释改进答案的人这样做。

【讨论】:

    猜你喜欢
    • 2014-07-30
    • 1970-01-01
    • 1970-01-01
    • 2015-06-28
    • 1970-01-01
    • 1970-01-01
    • 2020-09-09
    • 2015-06-03
    • 2010-10-29
    相关资源
    最近更新 更多