我正在尝试运行一个vagrant构建,它在Ubuntu Virtualbox VM中安装Oracle XE,然后运行SQL脚本来初始化Oracle Schema。
流浪汉的构建在这里:https://github.com/ajorpheus/vagrant-ubuntu-oracle-xe setup.sql作为oracle模块的init.pp的一部分运行(看起来接近该文件的末尾或搜索'oracle-script')。
我在运行这个流浪汉版本时遇到错误,只是被告知“没有任何更多细节,'oracle-script'位不成功。要弄清楚它是否是'oracle-script'位的问题,我将其解析为test-sql.pp:
file {
'/tmp/setup.sql':
ensure => file,
source => '/tmp/setup.sql';
}
exec { 'oracle-script':
path => ['/bin', '/u01/app/oracle/product/11.2.0/xe/bin'],
command => 'sqlplus system/manager@xe < /tmp/setup.sql',
require => [ File['/tmp/setup.sql']],
timeout => '0',
}
现在我有另一个问题(这就是这个问题)。 setup.sql创建一个表空间,在后续运行中,表空间创建应该失败,木偶脚本也应该失败。
我正在运行以下命令
puppet apply --verbose --debug test-sql.pp
输出总是表明成功结果:
debug: Exec[oracle-script](provider=posix): Executing 'sqlplus system/manager@xe < /tmp/setup.sql'
debug: Executing 'sqlplus system/manager@xe < /tmp/setup.sql'
notice: /Stage[main]//Exec[oracle-script]/returns: executed successfully
但是,如果我手动运行相同的SQL脚本:
问题
为什么即使包含的SQL脚本没有,Puppet构建也不会失败?我应该查看SQL Plus的退出代码吗?
如何让puppet发出更详细的调试信息?我找到了this,并尝试了那里的建议。
在RTFM之后...我发现Puppet的exec必须是幂等的。但问题仍然存在,如果表空间已经存在,为什么木偶构建不会失败?
谢谢!
更新
添加logoutput后,根据下面的TheQ建议,我看到以下输出:
debug: Executing 'sqlplus system/manager@xe < /tmp/setup.sql'
notice: /Stage[main]//Exec[oracle-script]/returns:
notice: /Stage[main]//Exec[oracle-script]/returns: SQL*Plus: Release 11.2.0.2.0 Production on Sat Apr 5 16:02:37 2014
notice: /Stage[main]//Exec[oracle-script]/returns:
notice: /Stage[main]//Exec[oracle-script]/returns: Copyright (c) 1982, 2011, Oracle. All rights reserved.
notice: /Stage[main]//Exec[oracle-script]/returns:
notice: /Stage[main]//Exec[oracle-script]/returns:
notice: /Stage[main]//Exec[oracle-script]/returns: Connected to:
notice: /Stage[main]//Exec[oracle-script]/returns: Oracle Database 11g Express Edition Release 11.2.0.2.0 - 64bit Production
notice: /Stage[main]//Exec[oracle-script]/returns:
notice: /Stage[main]//Exec[oracle-script]/returns: create tablespace some_INDEX_50M datafile '~\u01\some_INDEX_50M.dbf' size 50m
notice: /Stage[main]//Exec[oracle-script]/returns: *
notice: /Stage[main]//Exec[oracle-script]/returns: ERROR at line 1:
notice: /Stage[main]//Exec[oracle-script]/returns: ORA-01543: tablespace 'SOME_INDEX_50M' already exists
notice: /Stage[main]//Exec[oracle-script]/returns:
notice: /Stage[main]//Exec[oracle-script]/returns:
notice: /Stage[main]//Exec[oracle-script]/returns: Disconnected from Oracle Database 11g Express Edition Release 11.2.0.2.0 - 64bit Production
notice: /Stage[main]//Exec[oracle-script]/returns: executed successfully
答案 0 :(得分:3)
这不能回答问题的所有部分,但如果使用logoutput,您应该会看到exec命令的更多输出。默认情况下,仅当exec检测到故障时才会显示输出,这在您的情况下似乎不会发生。
因此,关于#2,请尝试添加:
logoutput => 'true',
答案 1 :(得分:1)
我相信puppet根据被调用程序的返回代码检测脚本是否成功。默认情况下,sqlplus在关闭时返回0,无论会话期间可能运行了什么。
[oracle@bbdb2 ~]$ sqlplus / as sysdba
SQL*Plus: Release 11.2.0.3.0 Production on Thu Apr 17 08:47:08 2014
Copyright (c) 1982, 2011, Oracle. All rights reserved.
Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
SQL> select asdjkhasd from sadbjaksd;
select asdjkhasd from sadbjaksd
*
ERROR at line 1:
ORA-00942: table or view does not exist
SQL> quit
Disconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
[oracle@bbdb2 ~]$ echo $?
0
如果希望sqlplus以错误状态退出,可以使用when命令,例如
[oracle@bbdb2 ~]$ sqlplus / as sysdba
SQL*Plus: Release 11.2.0.3.0 Production on Thu Apr 17 08:48:17 2014
Copyright (c) 1982, 2011, Oracle. All rights reserved.
Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
SQL> whenever sqlerror exit failure;
SQL> select bogus from nowhere;
select bogus from nowhere
*
ERROR at line 1:
ORA-00942: table or view does not exist
Disconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
[oracle@bbdb2 ~]$ echo $?
1
注意后一种情况下的不同返回码。这应该足以让傀儡知道命令失败了。