Ask Your Question
0

Is there a way for puppet to maintain unique /etc/hosts file on each node?

asked 2016-03-04 10:40:16 -0500

billb gravatar image

I am integrating puppet into an environment with a few hundred servers. Each of these servers has an /etc/hosts file that is unique. I need puppet to maintain this file on each node. Whats the best way to do this?

edit retag flag offensive close merge delete

3 Answers

Sort by ยป oldest newest most voted
1

answered 2016-03-04 20:40:08 -0500

DarylW gravatar image

You ask how to maintain unique /etc/hosts, but you don't tell us what you want to maintain about them. Do they each have a known, preset arrangement? You could move the values into a %{clientcert} based hiera config if that is the case and manage them with the hosts resource.

https://docs.puppetlabs.com/puppet/la...

If they are to gain additional information, but maintain the values that were already present, then you could use the above mentioned file_line or concat solutions, or use the hosts resource.

I would assume that you would prefer to gather up the information from all of the servers, and then manage it centrally?

If you have some way to run a command remotely across all of your instances (capistrano, fabric, multi-ssh ) Then you could use puppet to describe what your resources would look like on each host. I'm not sure if there is a way to get a json/yaml representation directly, but you could at least gather it up in one place.

pi@raspberrypi ~ $ sudo puppet resource host
host { 'ip6-allnodes':
  ensure => 'present',
  ip     => 'ff02::1',
  target => '/etc/hosts',
}
host { 'ip6-allrouters':
  ensure => 'present',
  ip     => 'ff02::2',
  target => '/etc/hosts',
}
host { 'ip6-localnet':
  ensure => 'present',
  ip     => 'fe00::0',
  target => '/etc/hosts',
}
host { 'ip6-mcastprefix':
  ensure => 'present',
  ip     => 'ff00::0',
  target => '/etc/hosts',
}
host { 'localhost':
  ensure => 'present',
  ip     => '127.0.0.1',
  target => '/etc/hosts',
}
host { 'raspberrypi':
  ensure => 'present',
  ip     => '127.0.1.1',
  target => '/etc/hosts',
}
edit flag offensive delete link more
1

answered 2016-03-05 12:26:33 -0500

rjc gravatar image

Or you can simply use:

file { '/etc/hosts':
    source => "puppet:///modules/${module_name}/hosts.${::hostname}",
}
edit flag offensive delete link more
0

answered 2016-03-04 17:31:13 -0500

lavaman gravatar image

Either through file_lines (part of stdlib):

https://github.com/puppetlabs/puppetl...

Or through concat fragments (part of the concat module):

https://github.com/puppetlabs/puppetl...

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

Stats

Asked: 2016-03-04 10:40:16 -0500

Seen: 97 times

Last updated: Mar 05 '16