How to reuse Vagrant parameter with Chef

25 views
Skip to first unread message

Vincenzo D'Amore

unread,
Nov 16, 2016, 12:31:17 PM11/16/16
to Vagrant
I'm struggling to understand how to pass current vagrant configuration to chef.

For example during Vagrant provisioning I have this configuration:

config.vm.provider :aws do |aws, override|
   override.ssh.username = "ubuntu"
   ...
end

...

config.vm.provision :chef_solo do |chef|
  chef.json = {
      username: "ubuntu"
  }
  ...
end

Now how can I reuse the ssh username in chef-solo provisioning? I would like be able to write something like this:

config.vm.provision :chef_solo do |chef|
  chef.json = {
      username: config.ssh.username
  }
end

Any help highly appreciated :)

Alvaro Miranda Aguilera

unread,
Nov 16, 2016, 3:58:08 PM11/16/16
to vagra...@googlegroups.com

maybe:

username = "ubuntu"

config.vm.provider :aws do |aws, override|
   override.ssh.username = "#{username}"
   ...
end

...

config.vm.provision :chef_solo do |chef|
  chef.json = {
      username: "#{username}"
  }
  ...
end


?

--
Alvaro

Vincenzo D'Amore

unread,
Nov 17, 2016, 4:43:25 AM11/17/16
to Vagrant
Thanks it works 
Reply all
Reply to author
Forward
0 new messages