Skip to content Skip to sidebar Skip to footer

Get Puppet Build To Fail When The Contained Sql Script Fails Execution

I am attempting to run a vagrant build which installs Oracle XE in an Ubuntu Virtualbox VM and then runs an SQL script to initialize the Oracle Schema. The vagrant build is here :

Solution 1:

I believe puppet detects the success of the script based on the return code of the called program. By default, sqlplus returns 0 when you close it, regardless of what may have been ran during the session.

[oracle@bbdb2~]$ sqlplus /as sysdba

SQL*Plus: Release11.2.0.3.0 Production on Thu Apr 1708:47:082014

Copyright (c) 1982, 2011, Oracle.  All rights reserved.


Connected to:
Oracle Database 11g Enterprise Edition Release11.2.0.3.0-64bit Production
With the Partitioning, OLAP, Data Mining andReal Application Testing options

SQL>select asdjkhasd from sadbjaksd;
select asdjkhasd from sadbjaksd
                      *
ERROR at line 1:
ORA-00942: tableorview does not exist


SQL> quit
Disconnected from Oracle Database 11g Enterprise Edition Release11.2.0.3.0-64bit Production
With the Partitioning, OLAP, Data Mining andReal Application Testing options
[oracle@bbdb2~]$ echo $?
0

If you want sqlplus to exit with an error status, you can use the whenever command, e.g.

[oracle@bbdb2~]$ sqlplus /as sysdba

SQL*Plus: Release11.2.0.3.0 Production on Thu Apr 1708:48:172014

Copyright (c) 1982, 2011, Oracle.  All rights reserved.


Connected to:
Oracle Database 11g Enterprise Edition Release11.2.0.3.0-64bit Production
With the Partitioning, OLAP, Data Mining andReal Application Testing options

SQL>whenever sqlerror exit failure;
SQL>select bogus from nowhere;
select bogus from nowhere
                  *
ERROR at line 1:
ORA-00942: tableorview does not exist


Disconnected from Oracle Database 11g Enterprise Edition Release11.2.0.3.0-64bit Production
With the Partitioning, OLAP, Data Mining andReal Application Testing options
[oracle@bbdb2~]$ echo $?
1

Notice the different return code in the latter case. This should be enough to let puppet know the command failed.

Post a Comment for "Get Puppet Build To Fail When The Contained Sql Script Fails Execution"