LoginSignup
0
0

More than 5 years have passed since last update.

ChefTips: ohai の追いかけ方

Posted at

自動でOS上のいろいろな情報を取得してきてnode変数に格納してくれる Chef Ohai は便利ですが、どのKeyにどんなValueを入れてくれているのか探すのもそれはそれで骨が折れる作業です。

ohai を実際に実行して、目を皿にしながら読んでいってもいいのですが、下記のように chef-apply を使いながらみていくと楽ですよ、というお話です。

まず最上位の Key を取得します。

Shell-Out
$ chef-apply -e 'node.keys.map {|x| puts x}'
tags
etc
current_user
lsb
kernel
(中略)

次に etc Key の下のKeyを取得します。

Shell-Out
$ chef-apply -e 'node[:etc].keys.map {|x| puts x}'
passwd
group

どんどん下の階層に降りていきます。

Shell-Out
$ chef-apply -e 'node[:etc][:passwd].keys.map {|x| puts x}'
root
bin
daemon
adm
lp
(中略)

続々。。

Shell-Out
$ chef-apply -e 'node[:etc][:passwd][:root].keys.map {|x| puts x}'
dir
gid
uid
shell
gecos

最下層アタリ迄ついたなー、と思ったら、直接 nodeオブジェクトを puts してください。

Shell-Out
$ chef-apply -e 'puts node[:etc][:passwd][:root][:dir]'
/root

お疲れ様でした。

参考/引用: chef-solo,chef-shellより更にミニマムなchef-apply@Qiita

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0