I've been trying to finish up a playbook for deploying a new server. I'm struggling with changing data within brackets containing quotes via lineinfile
and a 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
After the playbook is executed, the desired line:
#hosts: ["localhost:5044"]
is not updated to reflect:
hosts: ["elk.home:5044"]
What I'm trying to achieve is:
#hosts: ["localhost:5044"]
is replaced with hosts: ["elk.home:5044"]
There are no errors generated. I've tried varying "
and '
along with escapes \
, but I can't get the expression correct. Any suggestions would be greatly appreciated!
Thanks seshadri_c and β.εηοιτ.βε!
I was able to reach a resolution with the following lines:
- 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
After completing the playbook, I had an issue with whitespace. I added two spaces that correctly modified the line
- 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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.