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] ----
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"
  "chef_client" => {
    "init_style" => "upstart",
    "server_url" => "http://chef.ws:4000"
  "set_fqdn" => 

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?

  • "@config[:chef_node_name]" should not have the double quotes. @config[:chef_node_name] is indeed an invalid hostname. – Kyle Mar 2 '12 at 0:27
  • @Kyle this was just an example, I tried several approaches. It doesnt really matter tough, because @config isn't available in roles-files ;( – wintersolutions Mar 2 '12 at 6:32

After so trial and error I'm quite sure the @config and node variables are not accessible in role files. My solution was to rewrite the hostname cookbook to look for an attribute nodename_as_fqdn and set it accordingly.

|improve this answer|||||

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:

depends "chef_hostname"

And then setting the hostname like:

hostname node.name
|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.