Version information
This version is compatible with:
- Puppet 3.x
- , , , , , , ,
Start using this module
Add this module to your Puppetfile:
mod 'treydock-dynamic_hosts', '0.0.1'
Learn more about managing modules with a PuppetfileDocumentation
puppet-dynamic_hosts
####Table of Contents
- Overview - What is the dynamic_hosts module?
- Usage - Configuration and customization options
- Use Cases - Real world usage scenerios?
- Development - Guide for contributing to the module
Overview
The dynamic_hosts module lets you create dynamic host entries based on a system's IP addresses.
Usage
Class: dynamic_hosts
By default the class performs no actions. The dynamic_hosts_entries
top-scope variable can be used to define dynamic_hosts::entry
resources.
class { 'dynamic_hosts': }
Example of a top-scope dynamic_hosts_entries
variable
$dynamic_hosts_entries = {
'example.local' => { 'ip_networks' => [
{'ip' => '10.0.2.1', 'network' => '10.0.2.0'},
{'ip' => '1.1.1.1', 'network' => '127.0.0.0'}],
}
}
The class can be defined with the entries
parameter to also create dynamic_hosts::entry
resources
class { 'dynamic_hosts':
entries => {
'example.local' => { ip_networks => [
{'ip' => '10.0.2.1', 'network' => '10.0.2.0'},
{'ip' => '1.1.1.1', 'network' => '127.0.0.0'}],
},
}
}
Parameters for dynamic_hosts
class
#####entries
The Hash that is passed to create_resources to define dynamic_hosts::entry
resources (defaults to an empty Hash).
The dynamic_hosts_entries
top-scope variable can be used in place of this parameter. The parameter's value takes presedence over the top-scope variable.
Defined type: dynamic_hosts::entry
Defines a /etc/hosts entry based on the ip_networks
Hash. If the system has an IP within the value of the network
Hash element, then the ip
value is assigned to the host entry.
The following example creates a /etc/hosts entry for example.local with the ip
value from the first hash with a matching network
value.
dynamic_hosts::entry { 'example.local':
ip_networks => [
{'ip' => '10.0.2.2', 'network' => '10.0.2.0'},
{'ip' => '1.1.1.1', 'network' => '127.0.0.0'}
],
}
Aliases can also be defined
dynamic_hosts::entry { 'example.local':
ip_networks => [
{'ip' => '10.0.2.2', 'network' => '10.0.2.0'},
{'ip' => '1.1.1.1', 'network' => '127.0.0.0'}
],
host_alises => ['example-foo.local', 'example-bar.local'],
}
Parameters for dynamic_hosts::entry
defined type
#####namevar
The defined type's name that sets the hostname of the /etc/hosts entry.
#####ip_networks
Array of Hashes where each Hash has the ip
of the host entry that's assigned if an interface matches the network
value. A Hash with network
set to 127.0.0.0
can be used as the "catch all".
#####host_fqdn
Sets the /etc/hosts entry's FQDN (defaults to namevar
).
#####host_aliases
Array of aliases for the /etc/hosts entry (defaults to undef).
#####ensure
Controls the existance of the /etc/hosts entry (defaults to 'present').
Function: find_ip_by_network
Returns the IP of the first network
match found from an Array of Hashes. Returns false if no match is found.
Each hash must have an ip
key and a network
key.
Examples for find_ip_by_network
function
In these examples, the puppet client has eth0 with network 10.0.2.0 and lo with 127.0.0.0.
$ip = find_ip_by_network({'ip' => '10.0.2.2', 'network' => '10.0.2.0'})
Would return: 10.0.2.2
$ip = find_ip_by_network({'ip' => '192.168.1.2', 'network' => '192.168.1.0'}, {'ip' => '1.1.1.1', 'network' => '127.0.0.0'})
Would return: 1.1.1.1
$ip = find_ip_by_network({'ip' => '192.168.1.2', 'network' => '192.168.1.0'})
Would return: false
- Type: rvalue
Use Cases
LDAP Automount
Scenerio:
A single infrastructure shares LDAP and a NFS server for home directories. Multiple data centers share these resources in seperate buildings.
All user home directories are automounted based on a single LDAP auto.home entry. Some of the systems are on a high-speed private network local to the NFS server, while others must use a 'public' network to access the NFS server.
NFS Server IPs:
- eth0: 1.1.1.10 (public LAN) (255.255.255.0)
- eth1: 192.168.2.10 (255.255.255.0)
- lo: 127.0.0.0
Client1 networks:
- eth0: 1.1.1.100 (public LAN) (255.255.255.0)
- eth1: 192.168.2.100 (255.255.255.0)
- lo: 127.0.0.0 (255.255.255.0)
Client2 networks:
- eth0: 1.1.2.100 (public LAN) (255.255.255.0)
- eth1: 10.0.1.10 (255.255.255.0)
- lo: 127.0.0.0
Solution:
In LDAP set the hostname for the NFS automount to something like automount-nfs-home.local then use this module to map that hostname to an IP based on the IPs available to each server.
The following would be defined in Puppet (this example is in YAML for readability).
dynamic_hosts_entries:
'automount-nfs-home.local':
ip_networks:
- ip: '192.168.2.10'
network: '192.168.2.0'
- ip: '1.1.1.10'
network: '127.0.0.0'
In the example above Client1 would be assigned this host entry
192.168.2.10 automount-nfs-home.local
'Client2' would be assigned this host entry
1.1.1.10 automount-nfs-home.local
Limitations
This module has been built on and tested against Puppet 2.7 and higher.
This module has been tested on:
- CentOS 5/6
- Scientific Linux 5/6
Development
Testing
Testing requires the following dependencies:
- rake
- bundler
Install gem dependencies
bundle install
Run unit tests
bundle exec rake test
If you have Vagrant >= 1.2.0 installed you can run acceptance tests
bundle exec rake acceptance
Dependencies
- puppetlabs/stdlib (>= 2.6.0)
<!DOCTYPE html> <!-- Hello future GitHubber! I bet you're here to remove those nasty inline styles, DRY up these templates and make 'em nice and re-usable, right? Please, don't. https://github.com/styleguide/templates/2.0 --> <html> <head> <meta http-equiv="Content-type" content="text/html; charset=utf-8"> <title>Page not found · GitHub Pages</title> <style type="text/css" media="screen"> body { background-color: #f1f1f1; margin: 0; font-family: "Helvetica Neue", Helvetica, Arial, sans-serif; } .container { margin: 50px auto 40px auto; width: 600px; text-align: center; } a { color: #4183c4; text-decoration: none; } a:hover { text-decoration: underline; } h1 { width: 800px; position:relative; left: -100px; letter-spacing: -1px; line-height: 60px; font-size: 60px; font-weight: 100; margin: 0px 0 50px 0; text-shadow: 0 1px 0 #fff; } p { color: rgba(0, 0, 0, 0.5); margin: 20px 0; line-height: 1.6; } ul { list-style: none; margin: 25px 0; padding: 0; } li { display: table-cell; font-weight: bold; width: 1%; } .logo { display: inline-block; margin-top: 35px; } .logo-img-2x { display: none; } @media only screen and (-webkit-min-device-pixel-ratio: 2), only screen and ( min--moz-device-pixel-ratio: 2), only screen and ( -o-min-device-pixel-ratio: 2/1), only screen and ( min-device-pixel-ratio: 2), only screen and ( min-resolution: 192dpi), only screen and ( min-resolution: 2dppx) { .logo-img-1x { display: none; } .logo-img-2x { display: inline-block; } } #suggestions { margin-top: 35px; color: #ccc; } #suggestions a { color: #666666; font-weight: 200; font-size: 14px; margin: 0 10px; } </style> </head> <body> <div class="container"> <h1>404</h1> <p><strong>There isn't a GitHub Page here.</strong></p> <p><em>Are you trying to publish one?</em> It may take up to ten minutes until your page is available. </p> <p> <a href="https://help.github.com/categories/20/articles">Read the full documentation</a> to learn how to set up <strong>GitHub Pages</strong><br /> for your repository, organization, or user account. </p> <div id="suggestions"> <a href="https://github.com/contact">Contact Support</a> — <a href="https://status.github.com">GitHub Status</a> — <a href="https://twitter.com/githubstatus">@githubstatus</a> </div> <a href="/" class="logo logo-img-1x"> <img width="32" height="32" title="" alt="" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAyRpVFh0WE1MOmNvbS5hZG9iZS54bXAAAAAAADw/eHBhY2tldCBiZWdpbj0i77u/IiBpZD0iVzVNME1wQ2VoaUh6cmVTek5UY3prYzlkIj8+IDx4OnhtcG1ldGEgeG1sbnM6eD0iYWRvYmU6bnM6bWV0YS8iIHg6eG1wdGs9IkFkb2JlIFhNUCBDb3JlIDUuMy1jMDExIDY2LjE0NTY2MSwgMjAxMi8wMi8wNi0xNDo1NjoyNyAgICAgICAgIj4gPHJkZjpSREYgeG1sbnM6cmRmPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5LzAyLzIyLXJkZi1zeW50YXgtbnMjIj4gPHJkZjpEZXNjcmlwdGlvbiByZGY6YWJvdXQ9IiIgeG1sbnM6eG1wPSJodHRwOi8vbnMuYWRvYmUuY29tL3hhcC8xLjAvIiB4bWxuczp4bXBNTT0iaHR0cDovL25zLmFkb2JlLmNvbS94YXAvMS4wL21tLyIgeG1sbnM6c3RSZWY9Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC9zVHlwZS9SZXNvdXJjZVJlZiMiIHhtcDpDcmVhdG9yVG9vbD0iQWRvYmUgUGhvdG9zaG9wIENTNiAoTWFjaW50b3NoKSIgeG1wT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Zl9wiHA63yDYieM7DnLP5CiAGsC7I5sgtYKJGWe2A8seFqgFJrJjEPY1Cn3pJ8/9W1e5VWsFDTEmFrBcoDhZJEQkXuhICMyKpjhahqN21hRYATKfUOlDmkygrR4o4C0VOLGJKrOITKB4jijzdXygBKixyC5TDQdnk/Pz8qRw6oOWGlsTKGOQW6OH6FBWsyePxdOXLTgxiyebILZCjz+GLgMIKnXNzc49YMlcRdHXcSwxFVgTInQhC9G33UhNoJLuqq6t345p9y3eUy8OTk5PjAHuI9uo4b07FBaOhsu0A4Unc+T1TU1Nj3KsSSE5yJ65jqF2DDd8QqWYmAZrIM2VlZTdnZmb6AbpdV9V6ec9znf5Q7HjYumdRE0JOp3MjitO4SFa+cZz8Umqe3TCbSLvdfkR/kWDdNQl5InuTcysOcpFT35ZrbBxx4p3JAHlZVVW1D/634VRt+FvLBgK/v5LV9WS+10xMTEwtRw7XvqOL+e2Q8V3AYIOIAXQ26/heWVnZCVfcyKHg2CBgTpmPmjYM8l24GyaUHyaIh7XwfR9ErE8qHoDfn2LTNAVC0HX6MFcBIP8Bi+6F6cdW/DICkANRfx99fEYFQ7Nph5i/uQiA214gno7K+guhaiKg9gC62+M8eR7XsBsYJ4ilam60Fb7r7uAj8wFyuwM1oIOWgfmDy6RXEEQzJMPe23DXrVS7rtyD3Df8z/FPgAEAzWU5Ku59ZAUAAAAASUVORK5CYII=" /> </a> <a href="/" class="logo logo-img-2x"> <img width="32" height="32" title="" alt="" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEAAAABACAYAAACqaXHeAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAyRpVFh0WE1MOmNvbS5hZG9iZS54bXAAAAAAADw/eHBhY2tldCBiZWdpbj0i77u/IiBpZD0iVzVNME1wQ2VoaUh6cmVTek5UY3prYzlkIj8+IDx4OnhtcG1ldGEgeG1sbnM6eD0iYWRvYmU6bnM6bWV0YS8iIHg6eG1wdGs9IkFkb2J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