Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question
    
"@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

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
share|improve this answer
up vote 2 down vote accepted

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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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