Skip to content
Snippets Groups Projects
Commit e4e9505e authored by Thomas Bellman's avatar Thomas Bellman
Browse files

Rework adding node itself to /etc/hosts.

We used to unconditionally add the name and IP address(es) for the
node itself to /etc/hosts when managing it using networking::hostsfile.
However, that is a bit unflexible, as it depends on facter(1) being
correct in guessing what the primary IPv4 and/or IPv6 address for the
node is.  That's not always the case.

Here, this is changed, so networking::hostsfile does not add the node
itself to /etc/hosts.  Instead, users must now include the new class
'networking::hostsfile::node_self' to get the old behaviour.

This change is strictly speaking not backwards compatible, but since
we never got around to publishing the previous version, no one will
suffer for the change.
parent 1f30484c
Branches
No related tags found
No related merge requests found
# Copyright (C) 2020 Thomas Bellman.
# Licensed under the GNU LGPL v3+; see the README file for more information.
/*
* Add entries for the node's own IP addresses to /etc/hosts.
*
* The addresses used are what facter(1) thinks are the "primary"
* addresses (IPv4 and IPv6) for the node, and might not always be
* what you want.
*/
class networking::hostsfile::node_self
{
include networking::hostsfile
$self_ipv4 = defined('$::ipaddress') ? {
true => $::ipaddress,
false => [],
}
$self_ipv6 = defined('$::ipaddress6') ? {
true => $::ipaddress6,
false => [],
}
networking::hostsfile::hostentries {
'0':
comment => [-1], # Magic, internal value
hosts => {
# Need quotes due to Puppet parser bug/limitation
"${::fqdn}" => { 'ip' => [ $self_ipv4, $self_ipv6 ] },
"${::hostname}" => { 'ip' => [ $self_ipv4, $self_ipv6 ] },
};
}
}
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
<% if has_variable?('::ipaddress') -%>
<%= @ipaddress + "\t" + @fqdn + " " + @hostname %>
<% end -%>
<% if has_variable?('::ipaddress6') -%>
<%= @ipaddress6 + "\t" + @fqdn + " " + @hostname %>
<% end -%>
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment