Inserting an entire block of configuration using lineinfile

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?

You can try to loop using with_items: and storing the regexs, lines, etc in variables.

(attachments)

email_smslogo.png
email_icon_phone.png
email_icon_skype.png
email_icon_location.png
email_icon_email.png
email_icon_linkedin.png
email_icon_website.png

Yep, +1 to this.

Sorry about the misbehaving application :slight_smile:

(attachments)

email_icon_linkedin.png
email_icon_location.png
email_icon_skype.png
email_smslogo.png
email_icon_email.png
email_icon_website.png
email_icon_phone.png

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% :slight_smile: