繁体   English   中英

Ansible 剧本 - 正则表达式 | 无法更改括号和引号中的数据

[英]Ansible playbook - regexp | unable to change data in brackets and quotes

我一直在尝试完成部署新服务器的剧本。 我正在努力通过lineinfile和正则表达式更改包含引号的括号内的数据:

- name: "Configuring: filebeat agent - configuring output to logstash"
  lineinfile:
    dest: "/etc/filebeat/filebeat.yml"
    regexp: '#hosts: ["localhost:5044"]'
    line: 'hosts: ["elk.home:5044"]'
  tags: application

执行剧本后,所需的行:

#hosts: ["localhost:5044"]

更新以反映:

hosts: ["elk.home:5044"]

我想要实现的是:

#hosts: ["localhost:5044"]替换为hosts: ["elk.home:5044"]

没有产生错误。 我已经尝试过改变"'以及转义\ ,但我无法正确表达。任何建议将不胜感激!

感谢 seshadri_c 和 β.εηοιτ.βε!

我能够通过以下几行达成解决方案:

- name: "Configuring: filebeat agent - enabling logstash output hosts"
  lineinfile:
    dest: "/etc/filebeat/filebeat.yml"
    regexp: '#hosts: \["localhost:5044"\]'
    line: 'hosts: ["elk.home:5044"]'
  tags: 
    - configuration
    - application
    - filebeat

完成剧本后,我遇到了空白问题。 我添加了两个正确修改行的空格

- name: "Configuring: filebeat agent - enabling logstash output hosts"
  lineinfile:
    dest: "/etc/filebeat/filebeat.yml"
    regexp: '#hosts: \["localhost:5044"\]'
    line: '  hosts: ["elk.home:5044"]'
  tags: 
    - configuration
    - application
    - filebeat

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM