Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to properly use Roles with Chef-solo

I am not sure that I understand how roles should be used with chef-solo. More specifically I am looking for answers to the following questions:

(i) What is the syntax for telling chef-solo to run with a certain role? I managed to use:

chef-solo --override-runlist "role["oracle"]"

but is it the "right" way to do it (I'd expect I wouldn't need to "override" anything in a standard use of a chef role)? Also, if I use this command does it also load all the attributes from the role I specify and not only the runlist?

(ii) Is there a way to have a "default" runlist referenced from solo.rb and then have some (or all) roles somehow "reference" it? I have a few recipes I need to run under all roles and environments and I rather not copy them to all of my role json files (for maintainability reasons).

(P.S. I am running chef-solo on windows, in case it somehow matters...)

like image 363
Grishezz Avatar asked Jul 13 '14 15:07

Grishezz


1 Answers

You can use the JSON Attributes argument to chef-solo.

Run

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

Where conf.rb sets the cookbook path, file cache path, and any other global settings you want to twiddle, and conf.json looks something like this:

{
  "some_attr": true,
  "run_list": [
    "role[solo_provisioned_node]",
    "recipe[mycookbook::myrecipe]"
  ]
}

or in the example you gave, just

{
  "run_list": [
    "role[oracle]"
  ]
}
like image 123
sirosen Avatar answered Oct 08 '22 20:10

sirosen