如何在Ansible YAML文件中的字符串中转义冒号? [英] How can escape colon in a string within an Ansible YAML file?

查看:676
本文介绍了如何在Ansible YAML文件中的字符串中转义冒号?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在安装过程中更改文件/var/www/kibana/config.js中的代码的一行

I want to change one line of my code in file /var/www/kibana/config.js during installation from

elasticsearch: "http://"+window.location.hostname+":9200"

elasticsearch: "http://192.168.1.200:9200"

我在这里尝试使用lineinfile来做到这一点,如下所示

Here I tried to use lineinfile to do that as show below

- name: Comment out elasticsearch the config.js to ElasticSearch server
  lineinfile:
    dest=/var/www/kibana/config.js
    backrefs=true
    regexp="(elasticsearch.* \"http.*)$"
    line="elasticsearch\: \" {{ elasticsearch_URL }}:{{ elasticsearch_port }} \" "
    state=present

我分别将变量{{elasticsearch_URL}}{{elasticsearch_port}}设置为http://192.168.1.2009200.

I have set variables of {{elasticsearch_URL}} and {{elasticsearch_port}} to http://192.168.1.200 and 9200, respectively.

这是我遇到的错误消息:

Here is the error message I met:

ERROR: Syntax Error while loading YAML script, /Users/shuoy/devops_workspace/ansible_work/logging-for-openstack/roles/kibana/tasks/Debian.yml
Note: The error may actually appear before this position: line 29, column 25

regexp="(elasticsearch.* \"http.*)$"
line="elasticsearch\: \" {{ elasticsearch_URL }}:{{ elasticsearch_port }} \" "
                    ^

推荐答案

,您需要将整行括在"中,其中出现:.

you need to enclose the entire line in ", where : appears.

lineinfile:
'dest=/var/www/kibana/config.js
backrefs=true
regexp="(elasticsearch.* \"http.*)$"
line="elasticsearch\: \ {{ elasticsearch_URL }}:{{ elasticsearch_port }} \ "
state=present'  

请参阅以下页面:
链接1 链接3

See these pages:
Link-1 Link-2 Link-3

这篇关于如何在Ansible YAML文件中的字符串中转义冒号?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆