Ukigumo Server をたてて([2013-04-22-1])
Puppet の実行結果を Ukigumo Server に投げていたところ、
マニフェスト自体に問題があって puppet agent が終了すると
Ukigumo Server で FAIL になるが、
インストールするパッケージがインストールできないなどで
適用できないものがあっても
Notice: Finished catalog run in 14.06 seconds
と最後まで行くと Ukigumo Server では SUCCESS になる。
puppet agent を手で叩いて、
インストールできないパッケージがあっても、
echo $? すると 0 が返っていることを確認。
ぐぐったところ
- puppet always has an exitcode of 0 - Google グループ
https://groups.google.com/forum/?fromgroups=#!topic/puppet-users/EouO8xXnxcs
を発見。
"--detailed-exitcodes" をつければよいらしい。
puppet help agent を見ると
* --detailed-exitcodes: Provide transaction information via exit codes. If this is enabled, an exit code of '2' means there were changes, an exit code of '4' means there were failures during the transaction, and an exit code of '6' means there were both changes and failures.
とあるので、exit code は
- 0: 変更なし
- 1: マニフェストに syntax error などの問題がある
- 2: 変更あり
- 4: 適用できなかったものがある
- 6: 変更があり、かつ、適用できなかったものがある
ということのよう。
exit code が 2 の時も SUCCESS として
Ukigumo Server に投げる必要がある。
Perl の "$?" は
- perlvar - perldoc.perl.org
http://perldoc.perl.org/perlvar.html
によると、上 8 bits が exit code で
下 8 bits が core dump や signal death といった mode of failure らしいので、
8 bit シフトすれば shell での exit code と同じものがとれる。
Ukigumo Server に投げる status は以下のようになる。
$args->{status} = ($? >> 8 == 0 || $? >> 8== 2 ) ? 1 : 2;