This is how I manage ifcfg files with puppet. I create a directory under files/
for each host, e.g.:
modules/network/files/foohostname/
modules/network/files/someotherhostname/
Then in modules/network/manifests/init.pp
I do the following:
- Copy all files in
modules/network/files/hostname/
to the network scripts directory on the host.
- Run
service network start
or /etc/init.d/network start
when any files are added/changed. I've found that service network start
will bring up any interfaces that are not up yet, but won't kill my existing network connections.
class network {
# copy all ifcfg files from files/hostname/ directory to network-scripts/
# other files in network-scripts/ will not be touched.
file { '/etc/sysconfig/network-scripts/':
recurse => true,
purge => false,
owner => root,
group => root,
ignore => '\.svn', # this is specific to me as I use svn.
source => "puppet:///modules/network/${hostname}/",
}
# if anything changes with the above File resource, then fire network start to bring them up.
# this won't restart the network, only bring up any ifaces that are not up yet.
exec{ 'network-ifup':
command => 'service network start',
refreshonly => true,
subscribe => File['/etc/sysconfig/network-scripts/'],
}
}
FYI some of the above may be a little CentOS/RHEL-specific.