Quotes in ansible lineinfile

前端 未结 4 725
灰色年华
灰色年华 2020-12-10 11:30

When I use lineinfile in ansible it is not writing \', \" characters lineinfile: \'dest=/home/xyz state=present line=\"CACHES=\"

4条回答
  •  伪装坚强ぢ
    2020-12-10 12:12

    If the content to be substituted is in a variable higher up in the playbook, it seems that you need to escape the escape characters instead of the quotes, something like this

    ---
    - hosts: tomcat
    
      vars:
        classpath: "CLASSPATH=\\\"$CATALINA_HOME/bin/foo.jar\\\""
    
      tasks:
    
        - lineinfile: dest="/tomcat/bin/setenv.sh" line="{{ classpath }}" state=present
    

    ends up with a line like this in the resulting file

    CLASSPATH="$CATALINA_HOME/bin/foo.jar"
    

提交回复
热议问题