你的剧本-regexp|无法改变的数据在方括号和报价

0

的问题

我一直在试图完成一个剧本对部署一个新的服务器。 我在努力与不断变化的数据在方括号内包含报价通过 lineinfile 和regex:

- 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"]

没有错误而产生的。 我已经尝试了不同的 "' 随着逃跑 \但是我不能获得表达正确的。 任何建议,将不胜感激!

ansible filebeat regexp-replace
2021-11-23 04:50:20
1

最好的答案

0

谢谢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
2021-11-26 02:10:47

其他语言

此页面有其他语言版本

Русский
..................................................................................................................
Italiano
..................................................................................................................
Polski
..................................................................................................................
Română
..................................................................................................................
한국어
..................................................................................................................
हिन्दी
..................................................................................................................
Français
..................................................................................................................
Türk
..................................................................................................................
Česk
..................................................................................................................
Português
..................................................................................................................
ไทย
..................................................................................................................
Español
..................................................................................................................
Slovenský
..................................................................................................................