Merge pull request 'feat: add management of /etc/hosts' (#28) from neoloc/hostsfile into develop
Reviewed-on: unkinben/puppet-prod#28
This commit is contained in:
commit
92b73019cd
@ -43,3 +43,18 @@ puppetdb::master::config::puppetdb_host: "%{lookup('profiles::puppet::puppetdb::
|
||||
|
||||
profiles::accounts::sysadmin::sshkeys:
|
||||
- ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQDZ8SRLlPiDylBpdWR9LpvPg4fDVD+DZst4yRPFwMMhta4mnB1H9XuvZkptDhXywWQ7QIcqa2WbhCen0OQJCtwn3s7EYtacmF5MxmwBYocPoK2AArGuh6NA9rwTdLrPdzhZ+gwe88PAzRLNzjm0ZBR+mA9saMbPJdqpKp0AWeAM8QofRQAWuCzQg9i0Pn1KDMvVDRHCZof4pVlHSTyHNektq4ifovn0zhKC8jD/cYu95mc5ftBbORexpGiQWwQ3HZw1IBe0ZETB1qPIPwsoJpt3suvMrL6T2//fcIIUE3TcyJKb/yhztja4TZs5jT8370G/vhlT70He0YPxqHub8ZfBv0khlkY93VBWYpNGJwM1fVqlw7XbfBNdOuJivJac8eW317ZdiDnKkBTxapThpPG3et9ib1HoPGKRsd/fICzNz16h2R3tddSdihTFL+bmTCa6Lo+5t5uRuFjQvhSLSgO2/gRAprc3scYOB4pY/lxOFfq3pU2VvSJtRgLNEYMUYKk= ben@unkin.net
|
||||
|
||||
|
||||
profiles::base::hosts::additional_hosts:
|
||||
- ip: 198.18.17.3
|
||||
hostname: prodinf01n01.main.unkin.net
|
||||
aliases:
|
||||
- prodinf01n01
|
||||
- puppet
|
||||
- puppetmaster
|
||||
- puppetca
|
||||
- ip: 198.18.17.4
|
||||
hostname: prodinf01n04.main.unkin.net
|
||||
aliases:
|
||||
- prodinf01n04
|
||||
- puppetdb
|
||||
|
||||
@ -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,
|
||||
|
||||
30
site/profiles/manifests/base/hosts.pp
Normal file
30
site/profiles/manifests/base/hosts.pp
Normal file
@ -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'),
|
||||
}
|
||||
}
|
||||
15
site/profiles/templates/base/hosts.erb
Normal file
15
site/profiles/templates/base/hosts.erb
Normal file
@ -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 -%>
|
||||
Loading…
Reference in New Issue
Block a user