問題があるルビースクリプトを書いています。まず全体像:
CLIからコマンドを実行すると:
$ mco rpc puppet last_run_summary
私はこの出力を得る:
epuppet01.example.com
Changed Resources: 0
Config Retrieval Time: 1.21247005462646
Config Version: 1377176819
Failed Resources: 1
Last Run: 1377241107
Out of Sync Resources: 1
Since Last Run: 195
Summary: {"events"=>{"total"=>1, "success"=>0, "failure"=>1},
"resources"=>
{"scheduled"=>0,
"total"=>8,
"skipped"=>7,
"out_of_sync"=>1,
"failed"=>1,
"changed"=>0,
"failed_to_restart"=>0,
"restarted"=>0},
"changes"=>{"total"=>0},
"version"=>{"config"=>1377176819, "puppet"=>"3.1.1"},
"time"=>
{"config_retrieval"=>1.21247005462646,
"total"=>1.85353105462646,
"last_run"=>1377241107,
"package"=>0.641061}}
Total Resources: 8
Total Time: 1.85353105462646
Type Distribution: {"Package"=>1}
私が望むのは、そのコマンドの出力を変数/オブジェクトにリダイレクト/取得することです。具体的には、要約から「失敗したリソース」部分または「失敗した」値のいずれかを取得したいと思います。
どのようにそれを行うことができますか??
これまでのコードは次のようになります。
def runSingle
cmd = []
cmd.push(which("mco", ["/usr/bin", "/opt/puppet/bin"]))
shell_command(cmd + ["rpc", "puppet", " last_run_summary", "-I"] + shell_escaped_nodes)
end
ありがとう!!