如何在Ansible YAML文件中的字符串中转义冒号?

 春天故事围脖_381_478 发布于 2023-01-02 10:52

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

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

elasticsearch: "http://192.168.1.200:9200"

在这里,我尝试使用lineinfile来执行此操作,如下所示

- 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分别.

这是我遇到的错误消息:

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 }} \" "
                    ^

小智.. 23

你需要将整行包含":出现的位置.

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

请参阅以下页面:
Link-1 Link-2 Link-3

撰写答案
今天,你开发时遇到什么问题呢?
立即提问
热门标签
PHP1.CN | 中国最专业的PHP中文社区 | PNG素材下载 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有