[chef] Writing a first library


Chronological Thread 
  • From: Andrey Brindeyev < >
  • To:
  • Subject: [chef] Writing a first library
  • Date: Mon, 4 May 2015 10:49:26 -0700

Hi, everybody!

I'm trying to write my first library in Chef 11.18.0 (chef-solo) and using this article as an example:

However, this piece of code isn't working for me:
libraries/sensitives_helper.rb:
  1. require 'chef/mixin/shell_out'
  2.  
  3. module SensitivesHelper
  4.  
  5.   include Chef::Mixin::ShellOut
  6.  
  7.   def self.retrieve_token(type, version)
  8.     Chef::Log.info "Retrieving sensitive for token #{type}, version #{version}"
  9.     cmd = shell_out!('/usr/local/bin/get-sensitives.sh', type, version)
  10.     Chef::Log.info "Retrieved sensitive token: #{cmd.stdout}"
  11.     cmd.stdout
  12.   end
  13.  
  14. end
  15.  
  16. Chef::Recipe.send(:include, SensitivesHelper)

When I try to use it in recipe, it's causing NoMethodError: undefined method `shell_out!' for SensitivesHelper:Module

Usage example:

user = ''
ruby_block "get sensitives" do
  block do
    user = SensitivesHelper.retrieve_token('a', 'b')
  end
end

Any help is appreciated.

--
Andrey.



Archive powered by MHonArc 2.6.16.

§