Sam
Sam

Reputation: 23

Automatic expansion of cluster using puppet

We are using puppet to configure our product for virtual images. We are using /etc/hosts to list the nodes in our cluster like this:

127.0.0.1 localhost
x.x.x.x node-1
y.y.y.y node-2
z.z.z.z node-3
x.x.x.x this_node_ip 

This file is the same on all nodes except for the this_node_ip that is unique for all nodes( needed by application that has to have common configuration)

Our problem comes with expansion where we want /etc/hosts to be distributed with new nodes on all machines automatically when a new node starts up and connects to puppet master.

Our thought was to have a puppet template for /etc/hosts that keeps it synced with a fact for this_node_ip but how do we add new nodes in to the template?

Is there someway to list all agents connected to master in a fact? So that we could populate our /etc/hosts with a for each loop based on connected agents? Template would in that case be something like:

<% @list_of_nodes.split(',').each |ip, hostname| %>
<%= ip %> <%= hostname%>
<% end -%>
<%= ipadress_eth0 %> this_node_ip

Currently our only idea on way forward is to have new nodes scp a new template to puppetmaster node with all nodes hardcoded to update /etc/hosts file of old nodes.

Upvotes: 2

Views: 249

Answers (1)

Felix Frank
Felix Frank

Reputation: 8223

Oh, please don't ;-)

Each of your machines can dynamically export its own node entry.

@@host { $fqdn: ip => $ipaddress, tag => 'my-tag-foobar' }

...and collect the exports from all peers

Host<<| tag == 'my-tag-foobar' |>>

Do set up PuppetDB on your master to allow this to work.

You should not manage /etc/hosts as a complete file, because you lose the flexibility that Puppet's host resource offers.

Upvotes: 1

Related Questions