Using Augeas to manage /etc/network/interfaces from Puppet

1,075 views
Skip to first unread message

Andrew Pollock

unread,
Oct 6, 2010, 2:31:07 PM10/6/10
to augeas...@redhat.com, puppet...@googlegroups.com, Bryan Kearney, Free Ekanayaka
Hi,

Sorry for the broad distribution, I'm not sure who best can help me.

I'm trying to add a new interface stanza to /etc/network/interfaces.

With augtool, I can accomplish this with the following:

set /files/etc/network/interfaces/iface[last()+1] bond1
set /files/etc/network/interfaces/iface[last()]/family inet
set /files/etc/network/interfaces/iface[last()]/method dhcp
set /files/etc/network/interfaces/iface[last()]/slaves eth2

I've been able to translate that to the following Puppet resource:

augeas { "bond1":
  context => "/files/etc/network/interfaces",
  changes => [
    "set iface[last()+1] bond1",
    "set iface[last()]/family inet",
    "set iface[last()]/method dhcp",
    "set iface[last()]/slaves eth2",
  ],
}

All good so far, except this will unconditionally create the interface stanza every time Puppet runs. That's fine, this is what the "onlyif" directive is for, right? I just can't make it work.

I'm a bit hazy on how "match" works. From augtool, I can go

match /files/etc/network/interfaces/iface[*]

and sort of get back a list of interface names. I was thinking that maybe I could do something with that, but I'm not entirely sure what.

I hear there's some user-contributed Augeas examples in a Puppet wiki somewhere, but I haven't been able to find them. Any pointers appreciated.

regards

Andrew

Rob McBroom

unread,
Oct 6, 2010, 3:22:44 PM10/6/10
to puppet...@googlegroups.com
On Oct 6, 2010, at 2:31 PM, Andrew Pollock wrote:

> I hear there's some user-contributed Augeas examples in a Puppet wiki somewhere, but I haven't been able to find them. Any pointers appreciated.


There is (and even I have a hard time finding it).

http://projects.puppetlabs.com/projects/puppet/wiki/Puppet_Augeas

You can usually avoid the ugly mess of using last() and onlyif, as shown in the wiki.

--
Rob McBroom
<http://www.skurfer.com/>

Andrew Pollock

unread,
Oct 6, 2010, 6:46:20 PM10/6/10
to Puppet Users
Fabulous, thank you! For the record, I'm using


augeas { "bond1":
context => "/files/etc/network/interfaces",
changes => [
"set iface[. = 'bond1'] bond1",
"set iface[. = 'bond1']/family inet",
"set iface[. = 'bond1']/method dhcp",
"set iface[. = 'bond1']/slaves eth2",
],
}

which appears to be working as desired.

Ryan Y. Coleman

unread,
Oct 6, 2010, 7:06:19 PM10/6/10
to puppet...@googlegroups.com, Bryan Kearney, Free Ekanayaka, augeas...@redhat.com
Also see this blog post: http://www.puppetlabs.com/blog/puppets-google-summer-of-code/ which discusses this possibly useful module: http://github.com/blkperl/puppet-network

> --
> You received this message because you are subscribed to the Google
> Groups "Puppet Users" group.
> To post to this group, send email to puppet...@googlegroups.com.
> To unsubscribe from this group, send email to
> puppet-users...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/puppet-users?hl=en.

Reply all
Reply to author
Forward
0 new messages