I do tests atm with Chef and I have a virtual machine which I'm cloning to generate new nodes. I do bootstrap with the knife command and the -N Parameter to give each host a nodename. The Problem is tough, that the hostname on the VM doesn't change and if I'm trying to bootstrap another client it fails because Chef has this node already signed up.
I did now try to set the hostname in my base Role with the hostname cookbok but when I run chef-client
it gives me a:
---- Begin output of hostname @config[:chef_node_name] ----
STDOUT:
STDERR: hostname: the specified hostname is invalid
---- End output of hostname @config[:chef_node_name] ----
Ran hostname @config[:chef_node_name] returned 1
The Attributes for the base Role are:
name "base"
description "Base role applied to all nodes"
override_attributes(
"chef_client" => {
"init_style" => "upstart",
"server_url" => "http://chef.ws:4000"
},
"set_fqdn" =>
"@config[:chef_node_name]"
)
run_list(
"recipe[hostname]",
"recipe[chef-client::delete_validation]",
"recipe[chef-client::service]"
)
Do I have a syntax error here in the set_fqdn or is the @config variable simply not accessible on the node? Is there a better way to set the hostname to the nodename?
After so trial and error I'm quite sure the
@config
andnode
variables are not accessible in role files. My solution was to rewrite the hostname cookbook to look for an attributenodename_as_fqdn
and set it accordingly.The node name is accessible on the node running chef through the
node.name
accessor.You can use the chef_hostname cookbook to set the hostname to the node name by putting this in your metadata.rb:
And then setting the hostname like: