puppet-prod/site/profiles/manifests/base/hosts.pp
Ben Vincent 95434214a9 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
2023-10-22 00:34:22 +11:00

31 lines
866 B
Puppet

# 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'),
}
}