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

Use 'ipv4' and 'ipv6' elements in hostsfile::hostentries.

As the parse_host_mac_ip_list() function now recommends not using the
'ip' element of its return value, instead using the 'ipv4' and 'ipv6'
elements, we should of course follow that ourselves.  Specifically,
this affected the networking::hostsfile::hostentries definition, which
used the 'ip' element.  We here change it to use the 'ipv4' and 'ipv6'
elements if present, but for backward compatibility it will still use
the 'ip' element if both 'ipv4' and 'ipv6' elements are missing.

The networking::hostsfile::node_self definition also needed to be
updated, but this does not affect users.
parent 88f59ebb
No related branches found
No related tags found
No related merge requests found
# Copyright (C) 2020 Thomas Bellman. # Copyright (C) 2020-2022 Thomas Bellman.
# Licensed under the GNU LGPL v3+; see the README file for more information. # Licensed under the GNU LGPL v3+; see the README file for more information.
...@@ -8,17 +8,28 @@ ...@@ -8,17 +8,28 @@
* Parameters: * Parameters:
* *
* - hosts Hash mapping from host names to address information. The * - hosts Hash mapping from host names to address information. The
* address information is in turn a hash, with a required item * address information is in turn a hash, with required items
* named 'ip', mapping to one or more IP addresses. * named 'ipv4' and 'ipv6', mapping to one or more IPv4 and
* IPv6 addresses.
* Example: * Example:
* { * {
* 'foo' => { 'ip' => '192.0.2.6' }, * 'foo' => { 'ipv4' => '192.0.2.6' },
* 'fie' => { 'ip' => ['192.0.2.7','2001:db8:1::7'] }, * 'fie' => { 'ipv4' => ['192.0.2.7'],
* 'fum' => { 'ip' => '192.0.2.8', 'mac' => '1:3:5:7:9:a' }, * 'ipv6' => ['2001:db8:1::7'] },
* 'fum' => { 'ipv4' => [], 'ipv6' => '2001:db8:1::8' },
* } * }
* The last entry in the example, "fum" has an additional item * As the last entry indicates, either element may be empty or
* 'mac', which is not used. * be a string instead of a list. Also, either but not both of
* the 'ipv4' and 'ipv6' elements may be entirely absent. For
* backward compatibility, an 'ip' element may be present
* instead of 'ipv4' and 'ipv6' elements; this may however be
* deprecated in the future.
*
* The data format is exactly what the parse_host_mac_ip_list()
* function returns.
*
* Lists of IP addresses may be nested. * Lists of IP addresses may be nested.
*
* It is legal for multiple hostnames to map to the same IP * It is legal for multiple hostnames to map to the same IP
* address. * address.
* *
......
# Copyright (C) 2020 Thomas Bellman. # Copyright (C) 2020-2022 Thomas Bellman.
# Licensed under the GNU LGPL v3+; see the README file for more information. # Licensed under the GNU LGPL v3+; see the README file for more information.
...@@ -26,8 +26,14 @@ class networking::hostsfile::node_self ...@@ -26,8 +26,14 @@ class networking::hostsfile::node_self
comment => [-1], # Magic, internal value comment => [-1], # Magic, internal value
hosts => { hosts => {
# Need quotes due to Puppet parser bug/limitation # Need quotes due to Puppet parser bug/limitation
"${::fqdn}" => { 'ip' => [ $self_ipv4, $self_ipv6 ] }, "${::fqdn}" => {
"${::hostname}" => { 'ip' => [ $self_ipv4, $self_ipv6 ] }, 'ipv4' => $self_ipv4,
'ipv6' => $self_ipv6,
},
"${::hostname}" => {
'ipv4' => $self_ipv4,
'ipv6' => $self_ipv6,
},
}; };
} }
} }
<% <%
# Copyright (C) 2020 Thomas Bellman. # Copyright (C) 2020-2022 Thomas Bellman.
# Licensed under the GNU LGPL v3+; see the README file for more information. # Licensed under the GNU LGPL v3+; see the README file for more information.
-%> -%>
<% if @xcomment != [-1] # Magic, internal, value for no header %> <% if @xcomment != [-1] # Magic, internal, value for no header %>
...@@ -8,7 +8,16 @@ ...@@ -8,7 +8,16 @@
<% <%
names_per_ip = { } names_per_ip = { }
@hosts.each do |name,addrinfo| @hosts.each do |name,addrinfo|
[addrinfo.fetch('ip', [])].flatten.each do |ipaddr| if not addrinfo.has_key?('ipv4') and not addrinfo.has_key?('ipv6')
# Backward compatibility in case user does not provide separate
# 'ipv4' or 'ipv6' elements.
all_ip_addrs = addrinfo.fetch('ip')
else
ipv4addrs = [addrinfo.fetch('ipv4', [])]
ipv6addrs = [addrinfo.fetch('ipv6', [])]
all_ip_addrs = ipv4addrs + ipv6addrs
end
all_ip_addrs.flatten.each do |ipaddr|
if names_per_ip.has_key?(ipaddr) if names_per_ip.has_key?(ipaddr)
names_per_ip[ipaddr] << name names_per_ip[ipaddr] << name
else else
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment