1

I am trying to setup my Chef-Zero provisioner to execute the run list from a nodes JSON file. This is what my Vagrantfile looks like.

# -*- mode: ruby -*-
# vi: set ft=ruby :

# Vagrantfile API/syntax version. Don't touch unless you know what you're doing!
VAGRANTFILE_API_VERSION = "2"

Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
  config.vm.box = "ubuntu-14.04_Base_image"

  config.vm.hostname = "app_node"
  config.omnibus.chef_version = '12.0.3'


  config.vm.provision "chef_zero" do |chef|
    chef.cookbooks_path = ["../kitchen/cookbooks", "../kitchen/site-cookbooks"]
    chef.roles_path = "../kitchen/roles"
    chef.data_bags_path = "../kitchen/data_bags"
    chef.nodes_path = "../kitchen/nodes"
    chef.node_name = "app_node"
  end
end

When I run vagrant up, I get the following output from the chef-zero provisioner.

==> default: Running provisioner: chef_zero...
==> default: Detected Chef (latest) is already installed
Generating chef JSON and uploading...
==> default: Warning: Chef run list is empty. This may not be what you want.
==> default: Running chef-zero...
==> default: stdin: is not a tty
==> default: [2015-01-08T01:19:51+00:00] INFO: Started chef-zero at http://localhost:8889 with repository at /tmp/vagrant-chef/bec99a1a4e96279669bc5bb3140c0f2e, /tmp/vagrant-chef/2cbca02c0b5c49646d765ae1c9c0738f
==> default:   One version per cookbook
==> default:   data_bags at /tmp/vagrant-chef/72ac2a17a7c339d91d27a954fc49f8c3/data_bags
==> default:   nodes at /tmp/vagrant-chef/83a9002a19a985bce4d26b8c9d050540/nodes
==> default:   roles at /tmp/vagrant-chef/9cdb44a6dfefce6070b32ff28cb96535/roles
==> default: [2015-01-08T01:19:51+00:00] INFO: Forking chef instance to converge...
==> default: [2015-01-08T01:19:51+00:00] INFO: *** Chef 12.0.3 ***
==> default: [2015-01-08T01:19:51+00:00] INFO: Chef-client pid: 1731
==> default: [2015-01-08T01:19:57+00:00] INFO: Run List is []
==> default: [2015-01-08T01:19:57+00:00] INFO: Run List expands to []
==> default: [2015-01-08T01:19:57+00:00] INFO: Starting Chef Run for jira
==> default: [2015-01-08T01:19:57+00:00] INFO: Running start handlers
==> default: [2015-01-08T01:19:57+00:00] INFO: Start handlers complete.
==> default: [2015-01-08T01:19:59+00:00] INFO: Chef Run complete in 1.831177529 seconds
==> default: [2015-01-08T01:19:59+00:00] INFO: Skipping removal of unused files from the cache
==> default: [2015-01-08T01:19:59+00:00] INFO: Running report handlers
==> default: [2015-01-08T01:19:59+00:00] INFO: Report handlers complete

My question is why was the runlist empty? I specified the nodes directory and the node name in the chef_zero provisioner. The JSON file that specifies the run list for "app_node" exists in the nodes directory and I can see that chef is copying up all the cookbook/nodes/roles files to the server correctly.

I feel like I am missing something here. Any help would be much appreciated. If anything is unclear let me know.

PaulM
  • 79
  • 1
  • 8
  • What does the json file specifying the runlist looks like (and how is it named) ? I may be wrong as I don't use chef_zero but the `nodes_path` is meant to save the node object at end of run, not to prepare it. Vagrant override anyway the runlist with a json file generated from the vagrantfile, so you should add the recipes and roles in your vagrantfile or use the `CUSTOM JSON DATA` option in your vagrant file (see [here](http://docs.vagrantup.com/v2/provisioning/chef_solo.html) for the doc about it) – Tensibai Jan 08 '15 at 08:38
  • The file is named "app_node.json" and looks like this " { "name": "app_node", "platform": "debian", "postgresql": { 'password': { "postgres": "foobar" }, "run_list": [ "role[foo]", "recipe[auth]", "recipe[postgres]" } ". Is there no way to point the Vagrantfile to use the attributes and runlist in my JSON file? – PaulM Jan 08 '15 at 17:30

4 Answers4

1

Vagrant's chef_zero provisioner is actually using chef-solo -c solo.rb -j dna.json. Your configuration in nodes is not used other than mounting the directories.

You can workaround this by doing something like this (assumes that nodes/hostname.json is the same name put in config.vm.hostname):

VAGRANTFILE_API_VERSION = "2"
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
  config.vm.box = "chef/centos-6.6"

  config.vm.hostname = "foobarhost"
  VAGRANT_JSON = JSON.parse(Pathname(__FILE__).dirname.join('../../nodes', "#{config.vm.hostname}.json").read)

  config.vm.provision :chef_solo do |chef|
    chef.cookbooks_path  = ["../../cookbooks", "../../site-cookbooks"]
    chef.roles_path      = "../../roles"
    chef.data_bags_path  = "../../data_bags"
    chef.verbose_logging = true

    chef.run_list = VAGRANT_JSON.delete('run_list') if VAGRANT_JSON['run_list']
    # Add JSON Attributes
    chef.json = VAGRANT_JSON
  end
end

Note I just use chef_solo, as what's the point of running chef_zero when it really calls chef_solo.

0

You aren't specifying a run list. The directory you're talking about is where the node data is stored, not where those JSON files are gotten. Chef has no idea what you are trying to do right now.

# -*- mode: ruby -*-
# vi: set ft=ruby :

# Vagrantfile API/syntax version. Don't touch unless you know what you're doing!
VAGRANTFILE_API_VERSION = "2"

Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
  config.vm.box = "ubuntu-14.04_Base_image"

  config.vm.hostname = "app_node"
  config.omnibus.chef_version = '12.0.3'


  config.vm.provision "chef_zero" do |chef|
    chef.cookbooks_path = ["../kitchen/cookbooks", "../kitchen/site-cookbooks"]
    chef.roles_path = "../kitchen/roles"
    chef.data_bags_path = "../kitchen/data_bags"
    chef.nodes_path = "../kitchen/nodes"
    chef.node_name = "app_node"
    chef.run_list = []
    chef.json = {}
  end
end

This should allow you to set your run list and include any JSON attributes you wanted to include with it.

http://docs.vagrantup.com/v2/provisioning/chef_common.html

Has more options you might want to consider if they meet your needs. :-)

Stephen Carman
  • 999
  • 7
  • 25
  • In my nodes directory there is a file "app_node.son" that looks like this. " { "name": "app_node", "platform": "debian", "postgresql": { 'password': { "postgres": "foobar" }, "run_list": [ "role[foo]", "recipe[auth]", "recipe[postgres]" } " So there is no way to use the run list and attributes from my JSON file? I understand that I could simply copy and paste the JSON into the Vagrant file, but I would like to keep my JSON files representing my nodes separate from my Vagrantfile. – PaulM Jan 08 '15 at 17:18
0

I am not sure how to specify a local directory (still researching), but when you specify this in the Vagrantfile in chef.run_list["stuff"], vagrant will put a /tmp/vagrant-chef/dna.json

It also creates a solo.rb, which will insert stuff like node_name, if chef.node_name is created.

  • Try to format your answer properly (there art tips for layout when answering on the right side) so users can read it easily :) – LinusGeffarth Jun 18 '15 at 00:28
0

Vagrant doesn't consult Chef about existing nodes. In order to use the Chef node file that you wrote, you'll need to tell vagrant about it. In your Vagrantfile, add this line beneath the line chef.node_name = "app_node":

chef.json = JSON.parse(File.read("../kitchen/nodes/app_node.json"))

Once you do that, Chef and Vagrant will both look for the node configuration data in the same place.

indirect
  • 3,470
  • 2
  • 25
  • 13