2013-04-22 Mon

[別の年の同じ日: 2003 2006 2007 2008 2009 2010 2011

Puppet 3 系の exit code はてぶ

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;


Ukigumo Server をたててみた はてぶ

- Ukigumo と serverspec で Puppet の継続的インテグレーション - Gosuke Miyashita
  http://mizzy.org/blog/2013/03/27/1/

のような環境を Solaris 上に作るため、
まずは Ukigumo Server をたててみた。

Ukigumo Server が依存するものはパッケージを作り、
Ukigumo Server は cpan にないので、
とりあえず、github から clone して利用。

SMF manifest は作っていないので、

plackup ./app.psgi


で起動している。

- puppet-ci-with-ukigumo.pl
  https://gist.github.com/mizzy/5252543

を自分の環境に合わせて書きかえ、
Puppet の実行結果を Ukigumo Server に投げるところまで確認。

パッケージに依存関係の漏れがあったので、
class の形にまとめて以下にはっておいた。

- ukigumo-server.pp
  https://gist.github.com/ftnk/5435400

Referrer (Inside):
[2013-04-22-2] Puppet 3 系の exit code