3

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?

wintersolutions
  • 143
  • 2
  • 11
  • `"@config[:chef_node_name]"` should not have the double quotes. @config[:chef_node_name] is indeed an invalid hostname. – Kyle Mar 02 '12 at 00: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 02 '12 at 06:32

2 Answers2

2

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.

wintersolutions
  • 143
  • 2
  • 11
0

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
lamont
  • 133
  • 5