Website Logo. Upload to /source/logo.png ; disable in /source/_includes/logo.html

Zuzur’s wobleg

technology, Internet, and a bit of this and that (with some dyslexia inside)

Notebook: Chef Interactive Testing Using Irb

| Comments

I’m using this trick a lot to check what are the values of attributes in chef nodes without having to navigate through the UI. You can do everything in the UI or whatnot (change attributes, save them …). I usually do that from the top of my chef repository, but you can specify any valid path to a proper knife or chef-client configuration when calling Chef::Config.from_file

Quite handy:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
[10:46:11]-erwan@ip-192-168-0-59:~/dev/chef-repo(master) > irb
1.9.2p320 :001 >
1.9.2p320 :001 > require 'rubygems'
false
1.9.2p320 :002 > require 'awesome_print'
false
1.9.2p320 :003 > require 'chef'
true
1.9.2p320 :004 > Chef::Config.from_file(".chef/knife.rb")
"none"
1.9.2p320 :015 > n = Chef::Node.load('build')
node[build]
1.9.2p320 :016 > n.ohai_time
1335465628.75024
1.9.2p320 :017 > n.ntp
#false, "service"=>"ntpd", "servers"=>["0.us.pool.ntp.org", "1.us.pool.ntp.org", "0.pool.ntp.org", "1.pool.ntp.org", "2.pool.ntp.org"]}, @override={...}, @current_override={"servers"=>["0.pool.ntp.org", "1.pool.ntp.org", "2.pool.ntp.org"]}, @automatic={...}, @current_automatic=nil, @current_nesting_level=[:ntp], @auto_vivifiy_on_read=false, @set_unless_value_present=false, @set_type=nil, @has_been_read=false>
1.9.2p320 :019 > n['ntp']['servers']
[
    [0] "0.pool.ntp.org",
    [1] "1.pool.ntp.org",
    [2] "2.pool.ntp.org"
]

Comments