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?

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

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=",

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="" prefix="24"/>
    <route gateway=""/>

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.