[chef] Overriding default attributes


Chronological Thread 
  • From: Leonard Messier < >
  • To:
  • Subject: [chef] Overriding default attributes
  • Date: Mon, 3 Feb 2014 14:08:27 +0100

Ohai there,

I'm quite new to chef, sorry for the noobish question. Here is my problem :

I had a set of recipes for my developpment machine that I used to run with sudo like this : 

sudo chef-solo -c config/solo.rb -j config/system.json

At some point, I decided to rework it from the ground up with chefspec testing which lead me to understand that using sudo was a very bad idea.

I included the community sudo cookbook in my kitchen, but I don't have a clue on how to override the default attributes being set on it. This is the last content of my system.json file.

{
  "run_list": [ "system::default" ],
  "override_attributes": {
    "authorization": {
      "sudo": {
        "prefix": "/etc",
        "groups": [ "virtualeo" ],
        "users":  [ "virtualeo" ],
        "passwordless": "true",
        "include_sudoers_d": "true"
      }
    }
  }
}

Launching the command in a ubuntu 13.04 that I virtualized for testing, I get the following result :

Starting Chef Client, version 11.4.4
Compiling Cookbooks...

================================================================================
Recipe Compile Error in /home/virtualeo/.oh-my-chef/cookbooks/system/recipes/default.rb
================================================================================


NoMethodError
-------------
undefined method `[]' for nil:NilClass


Cookbook Trace:
---------------
/home/virtualeo/.oh-my-chef/vendor/cookbooks/sudo/recipes/default.rb:20:in `from_file'
/home/virtualeo/.oh-my-chef/cookbooks/system/recipes/default.rb:1:in `from_file'


Relevant File Content:
----------------------
/home/virtualeo/.oh-my-chef/vendor/cookbooks/sudo/recipes/default.rb:

13: # Unless required by applicable law or agreed to in writing, software
14: # distributed under the License is distributed on an "AS IS" BASIS,
15: # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16: # See the License for the specific language governing permissions and
17: # limitations under the License.
18: #
19:
20>> prefix = node['authorization']['sudo']['prefix']
21:
22: package 'sudo' do
23: not_if 'sudo -V'
24: end
25:
26: if node['authorization']['sudo']['include_sudoers_d']
27: directory "#{prefix}/sudoers.d" do
28: mode '0755'
29: owner 'root'



[2014-02-03T13:54:31+01:00] ERROR: Running exception handlers
[2014-02-03T13:54:31+01:00] ERROR: Exception handlers complete
Chef Client failed. 0 resources updated
[2014-02-03T13:54:31+01:00] FATAL: Stacktrace dumped to /home/virtualeo/.chef/state/cache/chef-stacktrace.out
[2014-02-03T13:54:31+01:00] FATAL: NoMethodError: undefined method `[]' for nil:NilClass

What I understand from this stacktrace is that  « node['authorization']['sudo']['prefix'] » causes the error. 

I guess the solution is pretty straightforward but I'm stuck for now !

Thanks in advance
--
Léonard Messier




Archive powered by MHonArc 2.6.16.

§