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

查看:57
本文介绍了如何在 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'  

查看这些页面:
Link-1 Link-2 链接 3

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

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