Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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?

share|improve this question
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
add comment

2 Answers

up vote 2 down vote accepted

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=",
        }
share|improve this answer
add comment

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.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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