4

I'm developing a Chef cookbook that I'm testing with Vagrant and chef-solo. The recipes look at node.name to make certain decisions. In order to test various variants of that I would like to override that attribute for test runs from Vagrant. So I tried

Vagrant.configure("2") do |config|
  ...
  config.vm.provision :chef_solo do |chef|
    ...
    chef.json = {
      'name' => 'randomhostname',
    }
  end
end

but seems to have no effect.

I understand that the name attribute defaults to the hostname attribute, which is managed by ohai (see also this question), but is there a way to override the name attribute?

Community
  • 1
  • 1
Peter Eisentraut
  • 35,221
  • 12
  • 85
  • 90

3 Answers3

5

You should be able to use:

Vagrant.configure("2") do |config|
  ...
  config.vm.provision :chef_solo do |chef|
    ...
    chef.node_name = 'node_name'
    ...
  end
end
cassianoleal
  • 2,556
  • 19
  • 22
3

If name defaults to the hostname of the vm then could you just change the hostname?

config.vm.hostname = "new.host.name"
Matt Cooper
  • 9,962
  • 2
  • 31
  • 26
1

Nope, there is no way - it's a so called automatic attribute and therefore has always the highest priority and overwrites everything you specify. Is it possible for you to use a different attribute or which cookbook are you going to convince that the node's name is something different than Chef thinks?

cmur2
  • 2,614
  • 1
  • 20
  • 23