There are several options to run recipes:
- using chef-client with -z option
- using chef-apply
- using chef-solo
Before running Chef recipes on the machine, it should be prepared:
- install necessary software (ChefDK, etc)
- run script
chef-client -z whatever.rb
- whatever.rb
file '/tmp/x.txt' do
content 'hello world'
end
run with json config
chef-client -z -j my.json
-
specify recipes to run in json file
-
my.json
{
"run_list": [ "recipe[base::default]" ]
}
-
create cookbook 'base'
-
put attributes for the node in json file
-
config.json
{
"attr1": "v1",
"attr2": "v2"
}
- specify recipe using --override-runlist option
chef-client -z -j config.json --override-runlist "recipe[base::default]"
run:
chef-apply hello.rb
- hello.rb
file 'hello.txt' do
content 'Welcome to Chef'
end
- solo.rb
file_cache_path "/root/chef-solo"
cookbook_path "/root/chef-repo/cookbooks"
- attr.json
{
"run_list": [ "recipe[apt]", "recipe[phpapp]" ],
"nginx": {"domainname": "mysite.com", "port": 80}
}
run
root@intro:~/chef-repo#
chef-solo -c solo.rb -j attr.json
or specify recipe in command line:
chef-solo -c solo.rb -j attr.json -o apt
?? chef-solo -c solo.rb -j attr.json -o "recipe[apt]", "recipe[phpapp]"
== attributes in json ==