aΨVaN
aΨVaN

Reputation: 1146

Chef to pull from local directory

Usually Chef client in chef node pulls from chef server which has the changes. How do I point chef client to a local folder which has my changes. Will Chef Solo help

Upvotes: 0

Views: 500

Answers (1)

seshadri_c
seshadri_c

Reputation: 7350

I think you are on the right track. We can use chef-solo to have cookbooks locally and execute them directly on the nodes.

Let's take an example node node1.example.net, we can have a config file in it solo.rb (can be any name).

solo.rb

cookbook_path '/home/user/.chef/cookbooks'
file_cache_path '/home/user/.chef/cache'
role_path '/home/user/.chef/roles'
data_bag_path '/home/user/.chef/databags'

If we run chef-solo at this point

chef-solo -c /home/user/.chef/solo.rb

There will no run_list so nothing will happen, but a <node name>.json will be created in the .chef/nodes directory, like node1.example.net.json.

Now we can store the cookbooks under /home/user/.chef/cookbooks, and add the appropriate cookbooks in the run_list of the node1.example.net.json file.

Or we can supply an optional .json file with the runlist we need. Something like example.json:

{
  "name": "tftest-devops01.headquarters.healthedge.com",
  "chef_environment": "_default",
  "json_class": "Chef::Node",
  // some lines removed
  "run_list": [
    "recipe[my_cookbook]"
  ]
}

Then run as:

chef-solo -c solo.rb -j example.json

chef-zero

There is also a chef-zero, which can help run a "local" (in-memory) Chef server to mimic Chef server functionality allowing us to perform knife operations.

Upvotes: 1

Related Questions