Single node name for multiple hosts


#1

Does anyone use a single node name for a group of machines? For example…two nodes in the chef server.

  • workstation
  • server

Then any specific rules for a device could be executed based on hostname.


#2

I use the same chef node when i create autoscaling AMI’s in AWS. The nodes
run chef on start up to get any changes since creation. I do have a
separate org on my chef server though so they don’t get mixed in and i know
what nodes are not 1 to 1.

-Grant


#3

Thanks for the reply. Yeah just trying to get my head around the best practise way of setting up a small lab of 5 machines. Since they are all essentially identical anyway it sorta made sense to just use the same node name…and anyway, if I had to do something specific to a machine I could use a (if node.hostname == ) statement.


#4

doh. should have read the documenation.

https://docs.chef.io/nodes.html#about-node-names

“The name of each node must be unique within an organization” or else you get a “…your client_key may be invalid…” error


#5

Hi @trg

You can not use same node name for multiple nodes. If you try that, this is where you will get stuck: when you will try to bootstrap second node with same name as first, Chef will through error saying node name already exists.

You can use tags to do same operation on multiple nodes. You can query tag using knife exec.
This is how you can do that:

• Write following ruby code and save it to .chef/scripts/tag.rb:
	nodes.transform("tags:tag1"){|n| puts n.run_list.add("role[role1]"); n.save }
	
• Execute following command from chef repo:
	 knife exec tag.rb

This code snippet will add role1 to all the nodes having tag1 value

I hope this will help.