Version information
This version is compatible with:
- Puppet Enterprise 2019.8.x, 2019.7.x, 2019.5.x, 2019.4.x, 2019.3.x, 2019.2.x, 2019.1.x, 2019.0.x, 2018.1.x, 2017.3.x, 2017.2.x, 2017.1.x, 2016.5.x, 2016.4.x
- Puppet >= 4.0.0
- Gentoo, RedHat, Debian, Ubuntu, CentOS, Solaris, SLES, SLED, FreeBSD, Darwin, AIX
Start using this module
Documentation
hosts
A template-based module to manage /etc/hosts. The main goal for this module is to add entries for localhost and primary address based on existing ip-adresses on existing interfaces. Tested by me on Gentoo, SLES, RedHat, and OS X. But it should work or any Linux and Unix-like OS.
This module unconditionally overwrites your hosts file. You have been warned! There are two reasons that this is template-based.
1) Currently the default host type don't allow multiple IP for a hostname (not even a IPv4 and a IPv6).
2) I prefer to manage files with puppet exclusively, or not at all.
Usage
class { 'hosts': }
Parameters
file
The file to add host entries to.
- Default: '/etc/hosts'
lo_ipv4
List of IPv4 addresses for localhost. Empty list means no entry.
- Default: [ IPv4 loopback addresses ]
lo_ipv6
List of IPv6 addresses for localhost. Empty list means no entry.
- Default: [ IPv6 loopback addresses ]
lo_names
List of names for localhost.
- Default: [ 'localhost' ]
primary_ipv4
List of IPv4 addresses. Empty list means no entry.
- Default: [ IPv4 addresses (not loopback or multicast) ]
primary_ipv6
List of IPv6 addresses. Empty list means no entry.
- Default: [ IPv6 addresses (not loopback, multicast, or linklocal) ]
primary_names
List of names for primary addresses.
- Default: [ $::fqdn, $::hostname ]
one_primary_ipv4
If true, only use the first address from primary_ipv4
- Default: true
one_primary_ipv6
If true, only use the first address from primary_ipv6
- Default: true
enable_ipv4
If false, don't add IPv4 loopback or primary addresses. (IPv4 addresses from hosts::entries is still added)
- Default: true
enable_ipv6
If false, don't add IPv6 loopback or primary addresses. (IPv6 addresses from hosts::entries is still added)
- Default: true
entries
A hash with additional host entries to add. Entries in this hash overrides automatic hostentries for IP's on local interfaces. The content can be either comment => { ip => [ names ], ... } or just ip => [ names ].
- Default: {}
Example
class { 'hosts':
one_primary_ipv4 => false,
one_primary_ipv6 => false,
entries => { '192.168.2.1' => [ 'foo.example.org', 'foo' ] }
}
Hiera example
hosts::one_primary_ipv4: false
hosts::one_primary_ipv6: false
hosts::entries:
'::2':
- 'localhost2'
'Foocluster nodes':
'2001:db8:abba::1':
- 'node1.example.org'
- 'node1'
'2001:db8:abba::2':
- 'node2.example.org'
- 'node2'
3.1.0
Sort IP-adresses to make hosts content stable across runs.
3.0.0
Replace deprecated validate-functions with puppet-4 data types.
2.4.0
Converted to pdk.
2.3.1
Bugfix: Reject nil IP
2.3.0
Ability to merge entries by hiera
2.2.7
Bugfixes to fact handling.
2.2.6
Add boolean parameters enable_ipv4 & enable_ipv6
2.2.5
Use exceptions in custom fact.
2.2.4
Put standart ipaddress facts first in lists.
The purpose is to get the expected ip-address if using one_primary_ipv4 or one_primary_ipv6
2.2.3
Change order of IP loaders in facter to be compatible with AIX
2.2.2
Fixed so that hosts::entries in new format overrides IP's on local interfaces
2.2.1
Entries in hosts::entries can now be grouped, resulting in a comment before each group in /etc/hosts. Example,
hosts::entries:
'Foocluster nodes':
'2001:db8:abba::1':
- 'node1.example.org'
- 'node1'
'2001:db8:abba::2':
- 'node2.example.org'
- 'node2'
This change is backward compatible. The old data-structure still works as before.
2.2.0
Entries in hosts::entries now overrides IP's on local interfaces
2.1.1
Changed domain used as example.
2.1.0
Fallback to std fact values for IP-adresses if custom facts fails.
2.0.5
Support for AIX, by Maxime Anciaux.
2.0.4
Added support for Darwin (OS X)
2.0.3
Added compatibility for ruby18, with much help from Frank Wall
2.0.2
Added support for FreeBSD, by Frank Wall
2.0.1
Workaround for older facter not handling arrays
2.0.0
Rewriten the code to find the local IP-addresses, to use a custom fact which uses ruby class socket. This is to get better control than core-facts can supply. And to be able to use all addresses configured on an interface instead of just one.
The default is still to use just one address, but that is easy configured with parameters one_primary_ipv4 and one_primary_ipv6
Dependencies
- puppetlabs/stdlib (>= 4.13.0 < 7.0.0)