diff --git a/CHANGELOG.md b/CHANGELOG.md index 7aad88f..f6f3fae 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,93 +1,115 @@ +## 2015-xx-xx - Release ? + +##Summary + +##Fixes +- PR/4: Support for bootup configuration on interfaces enabled. (Thanks for the contribution to lbayerlein) + +##2015-04-04 - Release 1.4.3 + +##Summary +CI build testing added. + +##2015-03-31 - Release 1.4.2 + +###Fixes +- Typo in dns-nameservers fixed + +##2015-03-30 - Release 1.4.1 + +##Summary +New feature helper for configuring DNS nameservers and search via resolvconf. + ##2015-03-16 - Release 1.3.1 ###Summary Fixed issue #2 ###Fixes - bridge and bond resources were not able to access package names declared in params.pp ##2015-03-15 - Release 1.3.0 ###Summary New feature helper allows declaring static routes on interfaces. ###Features - feature helper of static routes added ##2015-03-12 - Release 1.2.1 ###Summary - Bugfix, to resolve dependency problems to newer versions of concat and stdlib modules. ###Features - feature helper for static routes added ###Fixes - Minor improvements in documentation - Metadata fixed. ##2015-02-26 - Release 1.2.0 ###Summary Introduction of feature helpers. Configurable bridge parameters extended. ###Features - feature helper tx_queue added for setting tx queue length of an interface - added attributes maxage and maxwait to bridge ##2015-02-05 - Release 1.1.1 ###Summary Documentation bugfixes. ###Features ###Bugfixes - requirements corrected - README links fixed ##2015-02-04 - Release 1.1.0 ###Summary Operating system support tested. Up and down hooks now available for many resources. ###Features - support for Debian 6 and Ubuntu 12.04 added to metadata.json - added support for up/down hooks to resources bond, bridge, dhcp, loopback and static ##2015-01-20 - Release 1.0.1 ###Summary Bugfix. ###Changes - Validation of bonding attributes fixed. ##2015-01-20 - Release 1.0.0 ###Summary Added support for bonding and removed the need of including the module. ###Changes - including the module is not necessary anymore ###Features - support for bonding devices ##2014-12-27 - Release 0.3.1 ###Summary Minor refactoring, documentation and metadata improvements. ####Fixes - Metadata fixes to improve quality measures. - Some lint warnings with bridge.pp fixed. - Documentation fixed. ##2014-12-27 - Release 0.3.0 ###Summary New feature for configuring bridge interfaces. diff --git a/Gemfile b/Gemfile new file mode 100644 index 0000000..84f2fc3 --- /dev/null +++ b/Gemfile @@ -0,0 +1,28 @@ +source ENV['GEM_SOURCE'] || "https://rubygems.org" + +group :development, :unit_tests do + gem 'rake', :require => false + gem 'rspec-puppet', :require => false + gem 'puppetlabs_spec_helper', :require => false + gem 'puppet-lint', :require => false + gem 'simplecov', :require => false + gem 'puppet_facts', :require => false + gem 'json', :require => false +end + +group :system_tests do + gem 'beaker-rspec', :require => false + gem 'serverspec', :require => false +end + +if facterversion = ENV['FACTER_GEM_VERSION'] + gem 'facter', facterversion, :require => false +else + gem 'facter', :require => false +end + +if puppetversion = ENV['PUPPET_GEM_VERSION'] + gem 'puppet', puppetversion, :require => false +else + gem 'puppet', :require => false +end diff --git a/README.markdown b/README.markdown index 15a43ac..6d7c452 100644 --- a/README.markdown +++ b/README.markdown @@ -1,282 +1,304 @@ # debnet # +[![Build Status](https://travis-ci.org/rtib/tib-debnet.svg?branch=master)](https://travis-ci.org/rtib/tib-debnet) ####Table of Contents 1. [Overview](#overview) 2. [Module Description - What the module does](#module-description) 3. [Setup - Basic usage of module debnet](#setup) * [Beginning with the module](#beginning-with-the-module) * [Available configuration methods](#available-configuration-methods) * [Configuring the loopback interface](#configuring-the-loopback-interface) * [Static IPv4 configuration](#static-ipv4-interface-configuration) * [DHCP configuration](#dhcp-configuration) * [Common attributes](#common-attributes) 4. [Advanced configuration methods](#advanced-configuration-methods) * [Raw interface configuration](#Raw-interface-configuration) * [Bridge configuration](#bridge-configuration) * [Bonding configuration](#bonding-configuration) * [Using Up and down command hooks](#using-up-and-down-command-hooks) 5. [Feature helpers](#feature-helpers) * [Queue length](#queue-length) * [Static routes](#static-routes) + * [DNS resolver settings](#dns-resolver-settings) ##Overview This module constructs the ```/etc/network/interfaces``` file on Debian based Linux distributions and enables an easy configuration of sophisticated network setups, such as bridges and bonding configurations. ##Module Description This module lets you use many ```debnet::iface``` resourses for setting up network interfaces. ##Setup Declaring a single resource of this module will cause debnet to take control over the file ```/etc/network/interfaces``` which than will contain stanzas generated by the module only. Every declaration of ```debnet::iface``` resources will create a corresponding stanza in ```/etc/network/interfaces```. ###Beginning with the module To start with the debnet module the node can simply declare resources. Many nodes need at least a loopback interface which might look like: ```puppet debnet::iface::loopback { 'lo': } ``` Many other declaration may follow. Each of which will create an interface configuration. There are specialized resources available for many kind of configuration tasks, however, you may also use the simple ```debnet::iface``` resource to create generic interface stanzas. Be aware, that the specialized resources do some more validation, which makes the configuration less error prone. ###Available configuration methods The resource ```debnet::iface``` implements different configuration methods also available for the interfaces(5) stanzas. Currently supported methods are: * loopback * static * dhcp * manual ###Configuring the loopback interface Currently there is only a single way to create a configuration on the loopback interface. ```puppet debnet::iface::loopback { 'lo': } ``` ###Static IPv4 interface configuration For a static IP configuration the attributes address and netmask are mandatory. Attributes broadcast, gateway, pointopoint, hwaddress, mtu and scope are optional. ```puppet debnet::iface::static { 'eth0': address => '192.168.0.10', netmask => 24, gateway => '192.168.0.1', } ``` Available attributes: * ```ifname``` - (string) iface name (default: ```title```) * ```address``` - (dotted-quad) static address (mandatory) * ```netmask``` - (int or dotted-quad) netmask (mandatory) * ```broadcast``` - (dotted-quad) broadcast address (optional) * ```metric``` - (int) metric for routing protocols * ```gateway``` - (dotted-quad) gateway to set default route * ```pointopoint``` - (dotted-quad) point-to-point address * ```hwaddress``` - (macaddress) hardware address to override with * ```mtu``` - (int) interface MTU * ```scope``` - (string) address scope ###DHCP configuration Configuring an interface by dhcp is enabled through method set to according. Optional attributes hostname, metric, leasetime, vendor, client and hwaddress may be set. ```puppet debnet::iface::dhcp { 'eth0': } ``` Available attributes: * ```ifname``` - (string) iface name (default: ```$title```) * ```metric``` - (int) metric for routing protocols * ```hwaddress``` - (macaddress) hardware address to override with (optional) * ```hostname``` - (string) hostname to send with DHCP REQUEST (optional) * ```leasetime``` - (int) leasetime to request (optional) * ```vendor``` - (string) vendor id to send with request (optional) * ```client``` - (string) client id to send with request (optional) ###Common attributes Many resource types have some common attributes. These are: * ```auto``` - (bool) allow auto-bring-up interface (default: true) * ```allows``` - (array) allows-* features (default: []) * ```family``` - (string) only inet supported (default: inet) * ```order``` - (int) ordering of the resource (default: 0) ##Advanced configuration methods The module also gives a convenient way to declare more sofisticated network configurations like bonding of multiple interfaces or creating bridge devices. To leaverage from these it is necessary to learn how raw configuration of interfaces work by usage of ```debnet::iface``` type resource. This will allow the declaration of bonded interfaces through ```debnet::iface::bond``` and bridges through ```debnet::iface::bridge```. ###Raw interface configuration Using the specialised resources is convenient but not feasable in some circumstances. Therefore it might be necessery, however, to create configurations using the ```debnet::iface``` generic resource type. The above examples can be alternatively configured by using ```debnet::iface``` type as follows: Loopback interface: ```puppet debnet::iface { 'lo': method => 'loopback', } ``` Static interface: ```puppet debnet::iface { 'eth0': method => 'static', address => '192.168.0.10', netmask => 24, gateway => '192.168.0.1', } ``` DHCP configuration: ```puppet debnet::iface { 'eth0': method => 'dhcp', } ``` ###Bridge configuration Configuring a software bridge is enabled by declaring a resource of type ```debnet::iface::bridge```. Mandatory attribute is the method of configuration of the bridge interface. Depending on the method, the mandatory attributes of the choosen method are also mandatory for the bridge resource. Optional attributes are ports, stp, prio, fwdelay and hello. An example for configuring a bridge is: ```puppet debnet::iface::bridge { 'br0': ports => ['eth1','eth2'], stp => true, method => 'manual', } ``` The ```debnet::iface::bridge``` resource is defining interfaces for many ports of the bridge with manual configuration to inhibit multiple use of the same interface. Available attributes: * ```method``` - (string) interface configuration method (mandatory) * ```ifname``` - (string) iface name (default: ```$title```) * ```ports``` - (array) ports to be added (default: ```[]```) * ```stp``` - (bool) enable IEEE 802.1d spanning tree protocol (default: false) * ```prio``` - (int) STP bridge priority (optional) * ```fwdelay``` - (int) forward delay (optional) * ```hello``` - (int) hello timing (optional) * ```maxage``` - (int) max BPDU age (optional) * ```maxwait``` - (int) max seconds to wait for ports to come up (optional) ###Bonding configuration The module allows to bond multiple interfaces together by configuring a linux bonding device. ```puppet debnet::iface::bond { 'bond0': ports => ['eth1', 'eth2'], method => 'manual', } ``` Supported bonding modes are: balance-rr, active-backup, balance-xor, broadcast, 802.3ad, balance-tlb, balance-alb. Available attributes: * ```ports``` - (array) slave interfaces (mandatory) * ```mode``` - (string) bonding mode (default: active-backup) * ```miimon``` - (int) mii monitor timing (default: 100) * ```use_carrier``` - (bool) enable carrier sense (default: true) * ```updelay``` - (int) setting the updelay timer (optional) * ```downdelay``` - (int) setting the downdelay timer (optional) Such a configuration will create the interfaces(5) stanzas for many ports and the bonding device. The array in argument ports must have at least one item, and the first item will be configured as bond-primary. ###Using Up and down command hooks In many resources of the module you may use attributes ```ups```, ```downs```, ```pre-ups``` and ```post-downs``` declaring arrays of commands which will be called on the specific events. By declaring the attribute ```aux_ops``` with a hash, it is possilble to add auxiliary options to the interface stanza, which will be generated by using the key as option name and the value to the key as value. This obviously has the limitation of having every option name ones, however, the most important case this is useful, the up and down hooks can be handled through ```ups```, ```downs```, ```pre-ups``` and ```post-downs``` attributes. Many debnet resources allow to add commands to the usual up/down hooks. The attributes pre_ups, ups, downs and post_downs are available for many resources. Each of which are typed as array and many elements will be added in order as pre-up, up, down or post-down options, respectively. High care must be taken while using these attributes, since the module does not do any kind of checks. ```puppet debnet::iface::dhcp { 'eth0': ups => ['echo "eth0 is up"'], downs => ['echo "eth0 is going down"'] } ``` ##Feature helpers The module provides feature helpers to enable sofisticated configuration features to be added easily. ###Queue length If the setting of the txqueuelen feature of ethernet interfaces needs to done, the attribute ```tx_queue``` can be added to any resource type other than loopback. The helper adds an up command to set the transmit queue of the interface. In case of types bond and bridge, the up command is applied to the corresponding slave interfaces. ```puppet debnet::iface::dhcp { 'eth0': tx_queue => 50, } ``` Available attributes: * ```tx_queue``` - (int) length of the transmit queue (optional) ###Static routes Static routes can be added to any resource type which is configuring layer-3 of an interface. Declaring the ```routes``` attribute as a hash which is mapping gateway addresses (values) to specific destinations (keys). Destinations are declared by a dotted-quad and prefix length, the gateway addresses must be dotted-quads. Multiple routes may be declared. Many routes will be added as up and down commands to the containing interface. ```puppet debnet::iface::static { 'eth0': address => '192.168.0.10', netmask => 24, gateway => '192.168.0.1', routes => { '172.16.0.0/12' => '192.168.0.2', '10.0.0.0/8' => '192.168.0.3', }, } ``` Available attributes: * ```routes``` - (hash) maps routes to their gateways (optional) + +###DNS resolver settings +Many Debian installations make use of the resolvconf tools to setup the local +DNS resolver dynamically. Feature helpers ```dns_nameservers``` and +```dns_search``` enables to add presets to be passed to resolvconf scripts when +an interface is brought up. + +```puppet +debnet::iface::static { 'eth0': + address => '192.168.0.10', + netmask => 24, + gateway => '192.168.0.1', + dns_search => ['example.org', 'example.com'], + dns_nameservers => ['192.168.0.2', '192.168.0.3'], +} +``` + +Available attributes: +* ```dns_search``` - (array) DNS search list (optional) +* ```dns_nameservers``` - (array) DNS nameserver list (optional) diff --git a/manifests/iface.pp b/manifests/iface.pp index e4ce6f5..3c2068e 100644 --- a/manifests/iface.pp +++ b/manifests/iface.pp @@ -1,244 +1,268 @@ # == Define: iface # # Resource to define an interface configuration stanza within interfaces(5). # # == Parameters # # [*ifname*] => *(namevar)* - string # Name of the interface to be configured. # # [*method*] - string # Configuration method to be used. Supported methods are: # * loopback # * dhcp # * static # * manual # # [*auto*] - bool # Sets the interface on automatic setup on startup. This is affected by # ifup -a and ifdown -a commands. # # [*allows*] - array # Adds an allow- entry to the interface stanza. # # [*family*] - string # Address family. Currently, only inet family is supported. Support for # inet6 is comming soon. # # [*order*] - int # Order of the entry to be created in /etc/network/interfaces. Innate # odering is preset with default value of 10 for loopback and 20 for dhcp # and static stanzas. The order attribute of the resource is added to the # default value. # # [*hwaddress*] - string # The MAC address of the interface. This value is validated as standard # IEEE MAC address of 6 bytes, written hexadecimal, delimited with # colons (:) or dashes (-). # # [*hostname*] - string # The hostname to be submitted with dhcp requests. # # [*leasetime*] - int # The requested leasetime of dhcp leases. # # [*vendor*] - string # The vendor id to be submitted with dhcp requests. # # [*client*] - string # The client id to be submitted with dhcp requests. # # [*metric*] - int # Routing metric for routes added resolved on this interface. # # [*address*] - string # IP address formatted as dotted-quad for IPv4. # # [*netmask*] - string # Netmask as dotted-quad or CIDR prefix length. # # [*broadcast*] - string # Broadcast address as dotted-quad or + or -. # # [*gateway*] - string # Default route to be brought up with this interface. # # [*pointopoint*] - stirng # Address of the ppp endpoint as dotted-quad. # # [*mtu*] - int # Size of the maximum transportable unit over this interface. # # [*scope*] - string # Scope of address validity. Values allowed are global, link or host. # # [*pre_ups*] - array # Array of commands to be run prior to bringing this interface up. # # [*ups*] - array # Array of commands to be run after bringing this interface up. # # [*downs*] - array # Array of commands to be run prior to bringing this interface down. # # [*post_downs*] - array # Array of commands to be run after bringing this interface down. # # [*aux_ops*] - hash # Hash of key-value pairs with auxiliary options for this interface. # To be used by other debnet types only. # +# [*tx_queue*] - int +# Feature helper for setting tx queue on the interface. +# +# [*routes*] - hash +# Feature helper for setting static routes via the interface. +# +# [*dns_nameserver*] - array +# Feature helper to add a list of nameservers to be configures via resolvconf +# while the interface is set up. +# +# [*dns_search*] - array +# Feature helper to add a list of domain names as dns search via resolvconf +# while the interface is set up. +# # === Authors # # Tibor Repasi # # === Copyright # # Copyright 2015 Tibor Repasi # # 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. # define debnet::iface ( $method, $ifname = $title, $auto = true, $allows = [], $family = 'inet', $order = 0, # options for multiple methods $metric = undef, $hwaddress = undef, # options for method dhcp $hostname = undef, $leasetime = undef, $vendor = undef, $client = undef, # options for method static $address = undef, $netmask = undef, $broadcast = undef, $gateway = undef, $pointopoint = undef, $mtu = undef, $scope = undef, # up and down commands $pre_ups = [], $ups = [], $downs = [], $post_downs = [], # auxiliary options $aux_ops = {}, # feature-helpers $tx_queue = undef, $routes = {}, + $dns_nameservers = undef, + $dns_search = undef, ) { include debnet validate_string($ifname) validate_bool($auto) validate_array($allows) validate_re($family, '^inet$' ) validate_re($method, '^loopback$|^dhcp$|^static$|^manual$') validate_hash($aux_ops) validate_array($pre_ups) validate_array($ups) validate_array($downs) validate_array($post_downs) if $tx_queue { validate_re($tx_queue, '^\d+$') } if $routes { validate_hash($routes) } + if $dns_nameservers { + validate_array($dns_nameservers) + } + if $dns_search { + validate_array($dns_search) + } case $method { 'loopback' : { concat::fragment { 'lo_stanza': target => $debnet::params::interfaces_file, content => template('debnet/loopback.erb'), order => 10 + $order, } } 'dhcp' : { if !defined(Package[$debnet::params::dhclient_pkg]) { package { $debnet::params::dhclient_pkg: ensure => 'installed', } } if $hostname { validate_re($hostname, '^(?![0-9]+$)(?!-)[a-zA-Z0-9-]{,63}(? $debnet::params::interfaces_file, content => template( 'debnet/iface_header.erb', 'debnet/inet_dhcp.erb', 'debnet/iface_aux.erb', 'debnet/iface_routes.erb'), order => 20 + $order, } } 'static' : { validate_re($address, '^(:?[0-9]{1,3}\.){3}[0-9]{1,3}$') validate_re($netmask, '^([0-9]{1,3}\.){3}[0-9]{1,3}$|^[0-9]{1,2}$') if $broadcast { validate_re($broadcast, '^([0-9]{1,3}\.){3}[0-9]{1,3}$|^[+-]$') } if $metric { validate_re($metric, '^\d+$') } if $gateway { validate_re($gateway, '(:?[0-9]{1,3}\.){3}[0-9]{1,3}$') } if $pointopoint { validate_re($pointopoint, '(:?[0-9]{1,3}\.){3}[0-9]{1,3}$') } if $hwaddress { validate_re($hwaddress, '^([0-9A-Fa-f]{2}[:-]){5}([0-9A-Fa-f]{2})$') } if $mtu { validate_re($mtu, '^\d+$') } if $scope { validate_re($scope, '^global$|^link$|^host$') } concat::fragment { "${ifname}_stanza": target => $debnet::params::interfaces_file, content => template( 'debnet/iface_header.erb', 'debnet/inet_static.erb', 'debnet/iface_aux.erb', 'debnet/iface_routes.erb'), order => 20 + $order, } } + 'manual' : { concat::fragment { "${ifname}_stanza": target => $debnet::params::interfaces_file, content => template( 'debnet/iface_header.erb', 'debnet/inet_manual.erb', 'debnet/iface_aux.erb'), order => 20 + $order, } } + default: { err('unrecognized method') } } } diff --git a/manifests/iface/bond.pp b/manifests/iface/bond.pp index 301a961..9507ac8 100644 --- a/manifests/iface/bond.pp +++ b/manifests/iface/bond.pp @@ -1,253 +1,270 @@ # == Define: iface::bond # # Resource to define a bonding interface configuration stanza within # interfaces(5). # # == Parameters # # [*ifname*] => *(namevar)* - string # Name of the interface to be configured. # # [*method*] - string # Configuration method to be used. # # [*auto*] - bool # Sets the interface on automatic setup on startup. This is affected by # ifup -a and ifdown -a commands. # # [*allows*] - array # Adds an allow- entry to the interface stanza. # # [*family*] - string # Address family. Currently, only inet family is supported. Support for # inet6 is comming soon. # # [*order*] - int # Order of the entry to be created in /etc/network/interfaces. Innate # odering is preset with default value of 10 for loopback and 20 for dhcp # and static stanzas. The order attribute of the resource is added to the # default value. # # [*hwaddress*] - string # The MAC address of the interface. This value is validated as standard # IEEE MAC address of 6 bytes, written hexadecimal, delimited with # colons (:) or dashes (-). # # [*hostname*] - string # The hostname to be submitted with dhcp requests. # # [*leasetime*] - int # The requested leasetime of dhcp leases. # # [*vendor*] - string # The vendor id to be submitted with dhcp requests. # # [*client*] - string # The client id to be submitted with dhcp requests. # # [*metric*] - int # Routing metric for routes added resolved on this interface. # # [*address*] - string # IP address formatted as dotted-quad for IPv4. # # [*netmask*] - string # Netmask as dotted-quad or CIDR prefix length. # # [*broadcast*] - string # Broadcast address as dotted-quad or + or -. # # [*gateway*] - string # Default route to be brought up with this interface. # # [*pointopoint*] - stirng # Address of the ppp endpoint as dotted-quad. # # [*mtu*] - int # Size of the maximum transportable unit over this interface. # # [*scope*] - string # Scope of address validity. Values allowed are global, link or host. # # [*pre_ups*] - array # Array of commands to be run prior to bringing this interface up. # # [*ups*] - array # Array of commands to be run after bringing this interface up. # # [*downs*] - array # Array of commands to be run prior to bringing this interface down. # # [*post_downs*] - array # Array of commands to be run after bringing this interface down. # # [*aux_ops_*] - hash # Hash of key-value pairs with auxiliary options for this interface. # To be used by other debnet types only. # # [*aux_ops*] - hash # Hash of key-value pairs with auxiliary options for this interface. # To be used by other debnet types only. # +# [*tx_queue*] - int +# Feature helper for setting tx queue on the interface. +# +# [*routes*] - hash +# Feature helper for setting static routes via the interface. +# +# [*dns_nameserver*] - array +# Feature helper to add a list of nameservers to be configures via resolvconf +# while the interface is set up. +# +# [*dns_search*] - array +# Feature helper to add a list of domain names as dns search via resolvconf +# while the interface is set up. +# # === Authors # # Tibor Repasi # # === Copyright # # Copyright 2015 Tibor Repasi # # 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. # define debnet::iface::bond( $method, $ifname = $title, $auto = true, $allows = [], $family = 'inet', $order = 0, # bond options $ports = [], $mode = 'active-backup', $miimon = 100, $use_carrier = true, $updelay = undef, $downdelay = undef, # options for multiple methods $metric = undef, $hwaddress = undef, # options for method dhcp $hostname = undef, $leasetime = undef, $vendor = undef, $client = undef, # options for method static $address = undef, $netmask = undef, $broadcast = undef, $gateway = undef, $pointopoint = undef, $mtu = undef, $scope = undef, # up and down commands $pre_ups = [], $ups = [], $downs = [], $post_downs = [], # auxiliary options $aux_ops_master = {}, $aux_ops_slaves = {}, # feature-helpers $tx_queue = undef, $routes = {}, + $dns_nameservers = undef, + $dns_search = undef, ) { include debnet if !defined(Package[$debnet::params::ifenslave_pkg]) { package { $debnet::params::ifenslave_pkg: ensure => 'installed', } } - + validate_array($ports) if size($ports) == 0 { fail('Bonding needs at least one port to be declared!') } validate_re($mode, '^balance\-rr$|^active\-backup$|^balance\-xor$|^broadcast$|^802\.3ad$|^balance\-tlb$|^balance\-alb$') validate_re($miimon, '^\d+$') $bondopts0 = { 'bond-slaves' => 'none', 'bond-primary' => $ports[1], 'bond-mode' => $mode, 'bond-miimon' => $miimon, } validate_bool($use_carrier) if $updelay { validate_re($updelay, '^\d+$') $bondopts1 = {'bond-updelay' => $updelay} } else { $bondopts1 = {} } - + if $downdelay { validate_re($downdelay, '^\d+$') $bondopts2 = {'bond-downdelay' => $downdelay} } else { $bondopts2 = {} } - + debnet::iface { $ports: method => 'manual', auto => $auto, allows => $allows, family => $family, order => 50 + $order, mtu => $mtu, pre_ups => $pre_ups, ups => $ups, downs => $downs, post_downs => $post_downs, aux_ops => merge( $aux_ops_slaves, { 'bond-master' => $ifname, 'bond-mode' => $mode, 'bond-primary' => $ports[1], } ), tx_queue => $tx_queue, - routes => $routes, } debnet::iface { $ifname: - method => $method, - auto => $auto, - allows => $allows, - family => $family, - order => 60 + $order, - metric => $metric, - hwaddress => $hwaddress, - hostname => $hostname, - leasetime => $leasetime, - vendor => $vendor, - client => $client, - address => $address, - netmask => $netmask, - broadcast => $broadcast, - gateway => $gateway, - pointopoint => $pointopoint, - mtu => $mtu, - scope => $scope, - pre_ups => $pre_ups, - ups => $ups, - downs => $downs, - post_downs => $post_downs, - aux_ops => merge( + method => $method, + auto => $auto, + allows => $allows, + family => $family, + order => 60 + $order, + metric => $metric, + hwaddress => $hwaddress, + hostname => $hostname, + leasetime => $leasetime, + vendor => $vendor, + client => $client, + address => $address, + netmask => $netmask, + broadcast => $broadcast, + gateway => $gateway, + pointopoint => $pointopoint, + mtu => $mtu, + scope => $scope, + pre_ups => $pre_ups, + ups => $ups, + downs => $downs, + post_downs => $post_downs, + aux_ops => merge( $aux_ops_master, $bondopts0, $bondopts1, $bondopts2 ), - tx_queue => $tx_queue, - routes => $routes, + tx_queue => $tx_queue, + routes => $routes, + dns_nameservers => $dns_nameservers, + dns_search => $dns_search, } } \ No newline at end of file diff --git a/manifests/iface/bridge.pp b/manifests/iface/bridge.pp index 8b939c9..dd10d59 100644 --- a/manifests/iface/bridge.pp +++ b/manifests/iface/bridge.pp @@ -1,268 +1,286 @@ # == Define: iface::bridge # # Resource to define a bridge interface configuration stanza within # interfaces(5). # # == Parameters # # [*ifname*] => *(namevar)* - string # Name of the interface to be configured. # # [*method*] - string # Configuration method to be used. # # [*auto*] - bool # Sets the interface on automatic setup on startup. This is affected by # ifup -a and ifdown -a commands. # # [*allows*] - array # Adds an allow- entry to the interface stanza. # # [*family*] - string # Address family. Currently, only inet family is supported. Support for # inet6 is comming soon. # # [*order*] - int # Order of the entry to be created in /etc/network/interfaces. Innate # odering is preset with default value of 10 for loopback and 20 for dhcp # and static stanzas. The order attribute of the resource is added to the # default value. # # [*hwaddress*] - string # The MAC address of the interface. This value is validated as standard # IEEE MAC address of 6 bytes, written hexadecimal, delimited with # colons (:) or dashes (-). # # [*hostname*] - string # The hostname to be submitted with dhcp requests. # # [*leasetime*] - int # The requested leasetime of dhcp leases. # # [*vendor*] - string # The vendor id to be submitted with dhcp requests. # # [*client*] - string # The client id to be submitted with dhcp requests. # # [*metric*] - int # Routing metric for routes added resolved on this interface. # # [*address*] - string # IP address formatted as dotted-quad for IPv4. # # [*netmask*] - string # Netmask as dotted-quad or CIDR prefix length. # # [*broadcast*] - string # Broadcast address as dotted-quad or + or -. # # [*gateway*] - string # Default route to be brought up with this interface. # # [*pointopoint*] - stirng # Address of the ppp endpoint as dotted-quad. # # [*mtu*] - int # Size of the maximum transportable unit over this interface. # # [*scope*] - string # Scope of address validity. Values allowed are global, link or host. # # [*ports*] - array # Array of ports to be added to the bridge. # # [*stp*] - bool # Sets if bridge should implement spanning tree protocol. # # [*prio*] - int # Priority of the bridge for root selection within spanning tree. # # [*fwdelay*] - int # Sets the forward delay of the bridge in seconds. # # [*hello*] - int # Sets the bridge hello time in seconds. # # [*maxage*] - int # Maximum seconds of age of STP message. # # [*maxwait*] - int # Maximum seconds to wait for bridge interfaces to come up. # # [*pre_ups*] - array # Array of commands to be run prior to bringing this interface up. # # [*ups*] - array # Array of commands to be run after bringing this interface up. # # [*downs*] - array # Array of commands to be run prior to bringing this interface down. # # [*post_downs*] - array # Array of commands to be run after bringing this interface down. # # [*aux_ops*] - hash # Hash of key-value pairs with auxiliary options for this interface. # To be used by other debnet types only. # +# [*tx_queue*] - int +# Feature helper for setting tx queue on the interface. +# +# [*routes*] - hash +# Feature helper for setting static routes via the interface. +# +# [*dns_nameserver*] - array +# Feature helper to add a list of nameservers to be configures via resolvconf +# while the interface is set up. +# +# [*dns_search*] - array +# Feature helper to add a list of domain names as dns search via resolvconf +# while the interface is set up. +# # === Authors # # Tibor Repasi # # === Copyright # # Copyright 2015 Tibor Repasi # # 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. # define debnet::iface::bridge( $method, $ifname = $title, $auto = true, $allows = [], $family = 'inet', $order = 0, # bridge options $ports = [], $stp = false, $prio = undef, $fwdelay = undef, $hello = undef, $maxage = undef, $maxwait = undef, # options for multiple methods $metric = undef, $hwaddress = undef, # options for method dhcp $hostname = undef, $leasetime = undef, $vendor = undef, $client = undef, # options for method static $address = undef, $netmask = undef, $broadcast = undef, $gateway = undef, $pointopoint = undef, $mtu = undef, $scope = undef, # up and down commands $pre_ups = [], $ups = [], $downs = [], $post_downs = [], # auxiliary options $aux_ops = {}, # feature-helpers $tx_queue = undef, $routes = {}, + $dns_nameservers = undef, + $dns_search = undef, ) { include debnet if !defined(Package[$debnet::params::bridge_utils_pkg]) { package { $debnet::params::bridge_utils_pkg: ensure => 'installed', } } if size($ports) > 0 { $brports = join($ports, ' ') debnet::iface { $ports: method => 'manual', tx_queue => $tx_queue, } } else { $brports = 'none' } $bropts0 = {'bridge_ports' => $brports} if $hwaddress { $bropts1 = {'bridge_hw' => $hwaddress} } else { $bropts1 = {} } $bropts2 = {'bridge_stp' => $stp ? { true => 'on', default => 'off'} } if $stp { if $prio { validate_re($prio, '^\d+$') $bropts3 = { 'bridge_bridgeprio' => $prio} } else { $bropts3 = {} } if $fwdelay { validate_re($fwdelay, '^\d+$') $bropts4 = { 'bridge_fd' => $fwdelay } } else { $bropts4 = {} } if $hello { validate_re($hello, '^\d+$') $bropts5 = { 'bridge_hello' => $hello } } else { $bropts5 = {} } if $maxage { validate_re($maxage, '^\d+$') $bropts6 = { 'bridge_maxage' => $maxage } } else { $bropts6 = {} } if $maxwait { validate_re($maxwait, '^\d+$') $bropts7 = { 'bridge_maxwait' => $maxwait } } else { $bropts7 = {} } } debnet::iface { $ifname: - method => $method, - auto => $auto, - allows => $allows, - family => $family, - order => $order, - metric => $metric, - hostname => $hostname, - leasetime => $leasetime, - vendor => $vendor, - client => $client, - address => $address, - netmask => $netmask, - broadcast => $broadcast, - gateway => $gateway, - pointopoint => $pointopoint, - mtu => $mtu, - scope => $scope, - pre_ups => $pre_ups, - ups => $ups, - downs => $downs, - post_downs => $post_downs, - aux_ops => merge( + method => $method, + auto => $auto, + allows => $allows, + family => $family, + order => $order, + metric => $metric, + hostname => $hostname, + leasetime => $leasetime, + vendor => $vendor, + client => $client, + address => $address, + netmask => $netmask, + broadcast => $broadcast, + gateway => $gateway, + pointopoint => $pointopoint, + mtu => $mtu, + scope => $scope, + pre_ups => $pre_ups, + ups => $ups, + downs => $downs, + post_downs => $post_downs, + aux_ops => merge( $aux_ops, $bropts0, $bropts1, $bropts2, $bropts3, $bropts4, $bropts5, $bropts6, $bropts7), - routes => $routes, + routes => $routes, + dns_nameservers => $dns_nameservers, + dns_search => $dns_search, } } \ No newline at end of file diff --git a/manifests/iface/dhcp.pp b/manifests/iface/dhcp.pp index 15d4d56..611b4a3 100644 --- a/manifests/iface/dhcp.pp +++ b/manifests/iface/dhcp.pp @@ -1,136 +1,155 @@ # == Define: iface::dhcp # # Resource to define an interface configuration stanza within interfaces(5). # # == Parameters # # [*ifname*] => *(namevar)* - string # Name of the interface to be configured. # # [*method*] - string # Configuration method to be used. # # [*auto*] - bool # Sets the interface on automatic setup on startup. This is affected by # ifup -a and ifdown -a commands. # # [*allows*] - array # Adds an allow- entry to the interface stanza. # # [*family*] - string # Address family. Currently, only inet family is supported. Support for # inet6 is comming soon. # # [*order*] - int # Order of the entry to be created in /etc/network/interfaces. Innate # odering is preset with default value of 10 for loopback and 20 for dhcp # and static stanzas. The order attribute of the resource is added to the # default value. # # [*hwaddress*] - string # The MAC address of the interface. This value is validated as standard # IEEE MAC address of 6 bytes, written hexadecimal, delimited with # colons (:) or dashes (-). # # [*hostname*] - string # The hostname to be submitted with dhcp requests. # # [*leasetime*] - int # The requested leasetime of dhcp leases. # # [*vendor*] - string # The vendor id to be submitted with dhcp requests. # # [*client*] - string # The client id to be submitted with dhcp requests. # # [*metric*] - int # Routing metric for routes added resolved on this interface. # # [*pre_ups*] - array # Array of commands to be run prior to bringing this interface up. # # [*ups*] - array # Array of commands to be run after bringing this interface up. # # [*downs*] - array # Array of commands to be run prior to bringing this interface down. # # [*post_downs*] - array # Array of commands to be run after bringing this interface down. # # [*aux_ops*] - hash # Hash of key-value pairs with auxiliary options for this interface. # To be used by other debnet types only. # +# [*tx_queue*] - int +# Feature helper for setting tx queue on the interface. +# +# [*routes*] - hash +# Feature helper for setting static routes via the interface. +# +# [*dns_nameserver*] - array +# Feature helper to add a list of nameservers to be configures via resolvconf +# while the interface is set up. +# +# [*dns_search*] - array +# Feature helper to add a list of domain names as dns search via resolvconf +# while the interface is set up. +# # === Authors # # Tibor Repasi # # === Copyright # # Copyright 2014 Tibor Repasi # # 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. # define debnet::iface::dhcp ( $ifname = $title, $auto = true, $allows = [], $family = 'inet', $order = 0, $metric = undef, $hwaddress = undef, $hostname = undef, $leasetime = undef, $vendor = undef, $client = undef, # up and down commands $pre_ups = [], $ups = [], $downs = [], $post_downs = [], # auxiliary options $aux_ops = {}, # feature-helpers $tx_queue = undef, $routes = {}, + $dns_nameservers = undef, + $dns_search = undef, ) { include debnet validate_string($ifname) validate_bool($auto) validate_array($allows) validate_re($family, '^inet$' ) debnet::iface { $ifname : - method => 'dhcp', - hostname => $hwaddress, - metric => $metric, - leasetime => $leasetime, - vendor => $vendor, - client => $client, - hwaddress => $hwaddress, - pre_ups => $pre_ups, - ups => $ups, - downs => $downs, - post_downs => $post_downs, - aux_ops => $aux_ops, - tx_queue => $tx_queue, - routes => $routes, + method => 'dhcp', + auto => $auto, + hostname => $hwaddress, + metric => $metric, + leasetime => $leasetime, + vendor => $vendor, + client => $client, + hwaddress => $hwaddress, + pre_ups => $pre_ups, + ups => $ups, + downs => $downs, + post_downs => $post_downs, + aux_ops => $aux_ops, + tx_queue => $tx_queue, + routes => $routes, + dns_nameservers => $dns_nameservers, + dns_search => $dns_search, } } diff --git a/manifests/iface/static.pp b/manifests/iface/static.pp index 253ca02..9fcc0e5 100644 --- a/manifests/iface/static.pp +++ b/manifests/iface/static.pp @@ -1,154 +1,173 @@ # == Define: iface::static # # Resource to define simple interface with static configuration stanza within # interfaces(5). # # == Parameters # # [*ifname*] => *(namevar)* - string # Name of the interface to be configured. # # [*auto*] - bool # Sets the interface on automatic setup on startup. This is affected by # ifup -a and ifdown -a commands. # # [*allows*] - array # Adds an allow- entry to the interface stanza. # # [*family*] - string # Address family. Currently, only inet family is supported. Support for # inet6 is comming soon. # # [*order*] - int # Order of the entry to be created in /etc/network/interfaces. Innate # odering is preset with default value of 10 for loopback and 20 for dhcp # and static stanzas. The order attribute of the resource is added to the # default value. # # [*address*] - string # IP address formatted as dotted-quad for IPv4. # # [*netmask*] - string # Netmask as dotted-quad or CIDR prefix length. # # [*broadcast*] - string # Broadcast address as dotted-quad or + or -. # # [*gateway*] - string # Default route to be brought up with this interface. # # [*metric*] - int # Routing metric for routes added resolved on this interface. # # [*pointopoint*] - stirng # Address of the ppp endpoint as dotted-quad. # # [*mtu*] - int # Size of the maximum transportable unit over this interface. # # [*scope*] - string # Scope of address validity. Values allowed are global, link or host. # # [*hwaddress*] - string # The MAC address of the interface. This value is validated as standard # IEEE MAC address of 6 bytes, written hexadecimal, delimited with # colons (:) or dashes (-). # # [*pre_ups*] - array # Array of commands to be run prior to bringing this interface up. # # [*ups*] - array # Array of commands to be run after bringing this interface up. # # [*downs*] - array # Array of commands to be run prior to bringing this interface down. # # [*post_downs*] - array # Array of commands to be run after bringing this interface down. # # [*aux_ops*] - hash # Hash of key-value pairs with auxiliary options for this interface. # To be used by other debnet types only. # +# [*tx_queue*] - int +# Feature helper for setting tx queue on the interface. +# +# [*routes*] - hash +# Feature helper for setting static routes via the interface. +# +# [*dns_nameserver*] - array +# Feature helper to add a list of nameservers to be configures via resolvconf +# while the interface is set up. +# +# [*dns_search*] - array +# Feature helper to add a list of domain names as dns search via resolvconf +# while the interface is set up. +# # === Authors # # Tibor Repasi # # === Copyright # # Copyright 2015 Tibor Repasi # # 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. # define debnet::iface::static ( $address, $netmask, $ifname = $title, $auto = true, $allows = [], $family = 'inet', $order = 0, $broadcast = undef, $metric = undef, $gateway = undef, $pointopoint = undef, $hwaddress = undef, $mtu = undef, $scope = undef, # up and down commands $pre_ups = [], $ups = [], $downs = [], $post_downs = [], # auxiliary options $aux_ops = {}, # feature-helpers $tx_queue = undef, $routes = {}, + $dns_nameservers = undef, + $dns_search = undef, ) { include debnet validate_string($ifname) validate_bool($auto) validate_array($allows) validate_re($family, '^inet$' ) debnet::iface { $ifname: - method => 'static', - auto => $auto, - allows => $allows, - family => $family, - order => $order, - address => $address, - netmask => $netmask, - broadcast => $broadcast, - metric => $metric, - gateway => $gateway, - pointopoint => $pointopoint, - hwaddress => $hwaddress, - mtu => $mtu, - scope => $scope, - pre_ups => $pre_ups, - ups => $ups, - downs => $downs, - post_downs => $post_downs, - aux_ops => $aux_ops, - tx_queue => $tx_queue, - routes => $routes, + method => 'static', + auto => $auto, + allows => $allows, + family => $family, + order => $order, + address => $address, + netmask => $netmask, + broadcast => $broadcast, + metric => $metric, + gateway => $gateway, + pointopoint => $pointopoint, + hwaddress => $hwaddress, + mtu => $mtu, + scope => $scope, + pre_ups => $pre_ups, + ups => $ups, + downs => $downs, + post_downs => $post_downs, + aux_ops => $aux_ops, + tx_queue => $tx_queue, + routes => $routes, + dns_nameservers => $dns_nameservers, + dns_search => $dns_search, + } } diff --git a/metadata.json b/metadata.json index 5b42298..54b2528 100644 --- a/metadata.json +++ b/metadata.json @@ -1,23 +1,23 @@ { "name": "trepasi-debnet", - "version": "1.3.1", + "version": "1.4.3", "author": "T. Repasi", "summary": "Puppet module to manage /etc/network/interface file on Debian based Linux systems.", "tags": ["network","interfaces","ifup","ifdown","bridge","bonding"], "license": "Apache-2.0", "project_page": "https://github.com/rtib/tib-debnet.git", "source": "https://github.com/rtib/tib-debnet.git", "issues_url":"https://github.com/rtib/tib-debnet/issues", "operatingsystem_support": [ {"operatingsystem": "Debian", "operatingsystemrelease": ["6","7","8"] }, {"operatingsystem": "Ubuntu", "operatingsystemrelease": ["12.04","14.04"] } ], "dependencies": [ {"name":"puppetlabs/concat","version_requirement":">= 1.1.1 < 2.0.0"}, {"name":"puppetlabs/stdlib","version_requirement":">= 4.3.2 < 5.0.0"} ], "requirements": [ {"name": "pe", "version_requirement": "3.x" }, {"name": "puppet", "version_requirement": ">=2.7.20 <5.0.0" } ] } diff --git a/templates/iface_aux.erb b/templates/iface_aux.erb index 5feb952..22b6ecd 100644 --- a/templates/iface_aux.erb +++ b/templates/iface_aux.erb @@ -1,18 +1,24 @@ <% @aux_ops.keys.sort.each do |k| -%> <%= k -%> <%= @aux_ops[k] %> <% end -%> <% @pre_ups.each do |pu| -%> pre-up <%= pu %> <% end -%> <% if @tx_queue -%> up ip link set <%= @ifname -%> txqueuelen <%= @tx_queue %> <% end -%> <% @ups.each do |u| -%> up <%= u %> <% end -%> <% @downs.each do |d| -%> down <%= d %> <% end -%> <% @post_downs.each do |pd| -%> post-down <%= pd %> <% end -%> +<% if @dns_nameservers -%> + dns-nameservers <% @dns_nameservers.each do |ns| -%><%= ns -%> <% end %> +<% end -%> +<% if @dns_search -%> + dns-search <% @dns_search.each do |search| -%><%= search -%> <% end %> +<% end -%> diff --git a/templates/iface_header.erb b/templates/iface_header.erb index 6e888ff..ca01dbb 100644 --- a/templates/iface_header.erb +++ b/templates/iface_header.erb @@ -1,7 +1,9 @@ # interface <%= @ifname -%> configuration -<% if @auto -%> +<% if @auto == true -%> auto <%= @ifname %> +<% else -%> +<%= @ifname %> <% end -%> <% @allows.each do |s| -%> allow-<%= s -%> <%= @ifname %> -<% end -%> \ No newline at end of file +<% end -%>