feat: add management of /etc/hosts
- add class to manage the /etc/hosts file - add static hosts to /etc/hosts file via hiera array/hash
This commit is contained in:
@@ -26,6 +26,9 @@ class profiles::base (
|
||||
# include admin scripts
|
||||
include profiles::base::scripts
|
||||
|
||||
# include admin scripts
|
||||
include profiles::base::hosts
|
||||
|
||||
# include the python class
|
||||
class { 'python':
|
||||
manage_python_package => true,
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
# basic class to manage the /etc/hosts file from a template
|
||||
#
|
||||
# @param additional_hosts:
|
||||
# An array of hashes with ip/hostname/aliases
|
||||
# Aliases is an array in case there is a need for multiple aliases
|
||||
#
|
||||
# class { 'profiles::base::hosts':
|
||||
# additional_hosts => [
|
||||
# { 'ip' => '192.168.0.10', 'hostname' => 'server1.example.com', 'aliases' => ['server1'] },
|
||||
# { 'ip' => '192.168.0.11', 'hostname' => 'server2.example.com' },
|
||||
# # ... and so on
|
||||
# ],
|
||||
# }
|
||||
#
|
||||
class profiles::base::hosts (
|
||||
Array[Hash] $additional_hosts = []
|
||||
) {
|
||||
|
||||
$fqdn = $facts['networking']['fqdn']
|
||||
$hostname = $facts['networking']['hostname']
|
||||
|
||||
# Ensure the file exists and manage its content
|
||||
file { '/etc/hosts':
|
||||
ensure => file,
|
||||
owner => 'root',
|
||||
group => 'root',
|
||||
mode => '0644',
|
||||
content => template('profiles/base/hosts.erb'),
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
# /etc/hosts file managed by Puppet
|
||||
|
||||
# The following lines are desirable for IPv4 capable hosts
|
||||
127.0.0.1 <%= @fqdn %> <%= @hostname %>
|
||||
127.0.0.1 localhost.localdomain localhost
|
||||
127.0.0.1 localhost4.localdomain4 localhost4
|
||||
|
||||
# The following lines are desirable for IPv6 capable hosts
|
||||
::1 <%= @fqdn %> <%= @hostname %>
|
||||
::1 localhost.localdomain localhost
|
||||
::1 localhost6.localdomain6 localhost6
|
||||
|
||||
<% @additional_hosts.each do |host| -%>
|
||||
<%= host['ip'] %> <%= host['hostname'] %> <%= host['aliases'].join(' ') if host['aliases'] %>
|
||||
<% end -%>
|
||||
Reference in New Issue
Block a user