[chef] Re: Re: Re: chef and ruby scripts


Chronological Thread 
  • From: Daniel DeLeo < >
  • To:
  • Subject: [chef] Re: Re: Re: chef and ruby scripts
  • Date: Thu, 7 Nov 2013 09:12:29 -0800


On Wednesday, November 6, 2013 at 1:08 AM, Jasna Benčić wrote:

Looks handy but not quite what I'm looking for

I was looking for something that looks like the snippet below...  Where can I find what is inside Chef::  and that syntax? Below you see Config and Knife and Internet is very cheap with this kind of results :/

require("chef")
require("chef/knife")
Chef::Config.from_file(knifePath) #knifePath is declared a priori
cookbooks = Chef::Knife.run(["cookbook", "list"])
puts(cookbooks) # => nil

The code in knife commands is optimized for being a command line utility. This means that many of the methods will not have useful return values, they’ll print output to the terminal instead, and they might call exit at any time. So I would recommend against trying to use knife commands directly within a script, since they do things that library code should not do. One exception is if you simply want to string a handful of commands together one after the other.

Knife includes the `exec` command which is a way to execute scripts with all of your knife configuration already loaded and with some helper functions included into the root context. This might be closer to what you want: http://docs.opscode.com/knife_exec.html

-- 
Daniel DeLeo




Archive powered by MHonArc 2.6.16.

§