diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..6b6457f --- /dev/null +++ b/LICENSE @@ -0,0 +1,13 @@ +Copyright 2012 Andreas Jaggi + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. diff --git a/Modulefile b/Modulefile new file mode 100644 index 0000000..a6264cf --- /dev/null +++ b/Modulefile @@ -0,0 +1,11 @@ +name 'x-way-interfaces' +version '0.0.1' +source 'git://github.com/x-way/puppet-interfaces.git' +author 'Andreas Jaggi' +license 'Apache' +summary 'This module manages /etc/network/interfaces' +description 'This module manages the network interface configuration on Debian based systems.' +project_page 'http://github.com/x-way/puppet-interfaces' + +## Add dependencies, if any: +dependency 'ripienaar/concat', '>= 0.1.0' diff --git a/README.markdown b/README.markdown new file mode 100644 index 0000000..4c37b02 --- /dev/null +++ b/README.markdown @@ -0,0 +1,55 @@ +What is it? +=========== + +A Puppet module to manage /etc/network/interfaces. + +Usage: +------ + +Basic example which only configures the loopback interface: + +``` +include interfaces +interfaces::iface { 'lo': family => 'inet', method => 'loopback', auto => 1 } +``` + +Standard example with a regular Ethernet interface configured for DHCP: + +``` +include interfaces +interfaces::iface { 'eth0': family => 'inet', method => 'dhcp', auto => 1 } +``` + +Network interface with static addressing and VLAN with DHCP configuration: +``` +include interfaces +interfaces::iface { 'eth0': family => 'inet', method => 'static', options => ['address 192.0.2.1','netmask 255.255.255.0','gateway 192.0.2.2'], auto => 1 } +interfaces::iface { 'eth0.123': family => 'inet', method => 'dhcp', options => ['vlan_raw_device eth0'], auto => 1 } +``` + +Static IPv6 address configuration: +``` +include interfaces +interfaces::iface { 'eth0': family => 'inet6', method => 'static', options => ['address 2001:db8::1','netmask 64'], auto => 1 } +``` + +Dualstack configuration: +``` +include interfaces +interfaces::iface { 'eth0': family => 'inet', method => 'dhcp', auto => 1 } +interfaces::iface { 'eth0v6': ifname => 'eth0', family => 'inet6', method => 'static', options => ['address 2001:db8::1','netmask 64'], auto => 1 } +``` + +Reference: +---------- + +The puppet module directly implements the stanzas documented in interfaces(5). + +``` +interfaces::auto() +interfaces::allow($subsystem) +interfaces::mapping($script, $maps=[]) +interfaces::iface($family, $method, $options=[], $ifname=$name, $auto=0) +``` + +Currently the only shortcut is the $auto parameter of interfaces::iface which when set to 1 directly produces an interfaces::auto entry for the interface. diff --git a/manifests/allow.pp b/manifests/allow.pp new file mode 100644 index 0000000..267f859 --- /dev/null +++ b/manifests/allow.pp @@ -0,0 +1,7 @@ +define interfaces::allow ( $subsystem ) { + concat::fragment{"interfaces::allow-${subsystem}_${name}": + target => '/etc/network/interfaces', + content => "allow-${subsystem} ${name}\n\n", + } +} + diff --git a/manifests/auto.pp b/manifests/auto.pp new file mode 100644 index 0000000..aa09603 --- /dev/null +++ b/manifests/auto.pp @@ -0,0 +1,6 @@ +define interfaces::auto ( ) { + concat::fragment{"interfaces::auto_${name}": + target => '/etc/network/interfaces', + content => "auto ${name}\n\n", + } +} diff --git a/manifests/iface.pp b/manifests/iface.pp new file mode 100644 index 0000000..51f1e79 --- /dev/null +++ b/manifests/iface.pp @@ -0,0 +1,17 @@ +define interfaces::iface ( $family, $method, $options=[], $auto=0, $ifname="" ) { + if $ifname == "" { + $_ifname = $name + } else { + $_ifname = $ifname + } + + if $auto == 1 { + interfaces::auto { "${_ifname}": } + } + + $str = "iface ${_ifname} ${family} ${method}\n <%= options.join('\n ') %>\n\n" + concat::fragment{"interfaces::iface_${name}": + target => '/etc/network/interfaces', + content => inline_template($str), + } +} diff --git a/manifests/init.pp b/manifests/init.pp new file mode 100644 index 0000000..aa23cd2 --- /dev/null +++ b/manifests/init.pp @@ -0,0 +1,14 @@ +class interfaces { + concat{'/etc/network/interfaces': + owner => root, + group => root, + mode => 644, + notify => Service['networking'], + } + + concat::fragment{'interfaces_header': + target => '/etc/network/interfaces', + content => "# This file describes the network interfaces available on your system\n# and how to activate them. For more information, see interfaces(5).\n\n# Generated by puppet for ${fqdn}, DO NOT MODIFY!\n\n", + order => 01, + } +} diff --git a/manifests/mapping.pp b/manifests/mapping.pp new file mode 100644 index 0000000..195624e --- /dev/null +++ b/manifests/mapping.pp @@ -0,0 +1,7 @@ +define interfaces::mapping ( $script, $maps ) { + $str = "mapping ${name}\n script ${script}\n <%= maps.join('\n ') %>\n\n" + concat::fragment{"interfaces::mapping_${name}": + target => '/etc/network/interfaces', + content => inline_template($str), + } +}