I need to insert many lines of configuration and must use lineinfile or something similar.
The particular application in question also writes changes over time to other parts of the same file.
What is the best, cleanest way to accomplish this?
Is there a solution other than to string a bunch of lineinfile modules together?
For editing /etc/network/interfaces I use replace module with some patches.
- name: setup docker0 bridge
replace:
dest: /etc/network/interfaces
regexp: ‘^(# role docker.[\n\r]+)?iface\s+docker0\s+.[\n\r]+([ \t]+.[\n\r]?)(# role docker.*[\n\r]?)?’
replace: |
role docker script config BEGIN
iface docker0 inet static
bridge_ports none
bridge_stp off
bridge_maxwait 0
bridge_fd 0
address {{ docker_net_prefix }}.255.254
netmask 255.255.0.0
role docker script config END
append: yes
register: redocker
I have only trouble with missing trailing newline.
Dne středa, 9. dubna 2014 16:49:03 UTC+2 Michael Baydoun napsal(a):
That regex is a brutal one. Congrats. I think.
This is really why I prefer the template module 99.9999999% of the time. Ok, 100%