Weird situation - exec fails but Puppet 2.7 exits 2

32 views
Skip to first unread message

Amos Shapira

unread,
Nov 18, 2013, 10:34:31 PM11/18/13
to puppet...@googlegroups.com
Hello,

We are a long time Puppet 2.7 shop (installing latest Puppet 2.7 gems on deployments. In this particular build it picked up Puppet 2.7.23) and just discovered the following:

Executing a psql command like:

build   12-Nov-2013 04:30:16    debug: /Stage[main]/Buildeng_postgres::Service/Service[postgresql]: The container Class[Buildeng_postgres::Service] will propagate my refresh event
build   12-Nov-2013 04:30:16    debug: Class[Buildeng_postgres::Service]: The container Stage[main] will propagate my refresh event
build   12-Nov-2013 04:30:16    debug: Exec[create postgres user](provider=posix): Executing 'psql -U postgres -c "ALTER USER postgres WITH PASSWORD 'password';"'
build   12-Nov-2013 04:30:16    debug: Executing 'psql -U postgres -c "ALTER USER postgres WITH PASSWORD 'password';"'
build   12-Nov-2013 04:30:16    notice: /Stage[main]/Buildeng_postgres::Post_service/Buildeng_postgres::Create_user[postgres]/Exec[create postgres user]/returns: psql: FATAL:  the database system is starting up
build   12-Nov-2013 04:30:16    err: /Stage[main]/Buildeng_postgres::Post_service/Buildeng_postgres::Create_user[postgres]/Exec[create postgres user]: Failed to call refresh: psql -U postgres -c "ALTER USER postgres WITH PASSWORD 'password';" returned 2 instead of one of [0] at /home/ubuntu/puppet-cfg/buildeng-modules/buildeng_postgres/manifests/create_user.pp:10

The resource which creates this log is:

define buildeng_postgres::create_user ($password=undef) {

  require buildeng_postgres::service

  exec { 'create postgres user':
    subscribe   => Service['postgresql'],
    user        => $buildeng_postgres::params::user,
    command     => "psql -U ${buildeng_postgres::params::postgres_user} -c \"ALTER USER ${buildeng_postgres::params::postgres_user} WITH PASSWORD '${buildeng_postgres::params::postgres_password}';\"",
    refreshonly => true,
  }

}

Puppet registers the failure as an error ("2" is not an expected exit code of this Exec resource) but still exits with exit status "2" (with --detailed-exitcode).
I know why psql failed but that's besides the point - Puppet should have failed but it didn't.

Any idea why?

Thanks.

Felix Frank

unread,
Nov 19, 2013, 9:31:59 AM11/19/13
to puppet...@googlegroups.com
Hi,

if memory serves, --detailed-exitcode (one of the more annyoing
implications of --test) will return the number of resources that changed.

So are there any other things that puppet did during its run?

Generally, if you want to use the exit code of `puppet agent` (or apply)
to determine whether there were problems, you should avoid
--detailed-exitcode and --test.

HTH,
Felix
Reply all
Reply to author
Forward
0 new messages