Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I override the Chef node name in vagrant?

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?

like image 400
Peter Eisentraut Avatar asked Jan 13 '23 09:01

Peter Eisentraut


2 Answers

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
like image 191
cassianoleal Avatar answered Jan 28 '23 14:01

cassianoleal


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

config.vm.hostname = "new.host.name"
like image 27
Matt Cooper Avatar answered Jan 28 '23 14:01

Matt Cooper