4

I did not find any elegant way to add several lines to an existing file.

I noticed the Simple Text Patterns wiki page, but I have to add a block into /etc/network/interfaces.

Any clue?

3
  • 1
    augeas is the normal way
    – Sirex
    Jan 17, 2013 at 8:05
  • thx. I will give it a try
    – Mike Aski
    Jan 17, 2013 at 8:24
  • As a note, the question has been flaged to be closed by two people already. You might want to rephrase it.
    – raphink
    Jan 17, 2013 at 10:50

2 Answers 2

5

I agree that augeas is by far the best answer to what you are trying.

I would also recommend the file_line resource from the stdlib puppet library. It tends to be much more lightweight than augeas.

You would have to define one resource for each line, and if the order is important you can add dependencies between the invocations.

Sample usage:

        file_line { "no_ipv6_networking":
            path  => "/etc/sysconfig/network",
            line  => "NETWORKING_IPV6=no",
            match => "^NETWORKING_IPV6=",
        }
3

You coud use the augeas type for this, but the ideal solution would be to use netcf since you want to manage network interfaces.

Some time ago, I have started a Puppet Netcf provider. It is still not ready for production, but if you have some Ruby skills, it's probably the best solution for your need (and PRs are most definitely welcome, too).

The Netcf provider takes an XML interface definition as input, for example:

netcf_if {"eth1":
  ensure     => up,
  definition => '
<interface type="ethernet" name="eth1">
  <start mode="onboot"/>
  <protocol family="ipv4">
    <ip address="192.168.0.5" prefix="24"/>
    <route gateway="192.168.0.1"/>
  </protocol>
</interface>
';
}

You can find more examples of XML definitions in the Netcf repository.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .