Inserting an entire block of configuration using lineinfile

864 views
Skip to first unread message

Michael Baydoun

unread,
Apr 9, 2014, 10:49:03 AM4/9/14
to ansible...@googlegroups.com
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?

Tony Marin

unread,
Apr 9, 2014, 10:51:20 AM4/9/14
to ansible...@googlegroups.com

You can try to loop using with_items: and storing the regexs, lines, etc in variables.
--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
To post to this group, send email to ansible...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/80361127-7f35-4b21-8aa3-101efc777e53%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--
Swiss Mobility Solutions

Antonio Marin

IT Team Lead

Swiss Mobility Solutions

Office Telephone +34 966370055

Skype antonymcs

Location Av. Locutor Vicente Hipólito 39
03540 Alicante Spain

Email LinkedIn Website

Michael DeHaan

unread,
Apr 15, 2014, 4:36:35 PM4/15/14
to ansible...@googlegroups.com
Yep, +1 to this.

Sorry about the misbehaving application :)





Michael Heča

unread,
Apr 16, 2014, 3:58:00 PM4/16/14
to ansible...@googlegroups.com
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):

Michael DeHaan

unread,
Apr 16, 2014, 10:28:48 PM4/16/14
to ansible...@googlegroups.com
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% :)





--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
To post to this group, send email to ansible...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages