【发布时间】:2014-04-05 19:47:51
【问题描述】:
我正在尝试运行一个 vagrant build,它在 Ubuntu Virtualbox VM 中安装 Oracle XE,然后运行 SQL 脚本来初始化 Oracle Schema。
vagrant build 在这里:https://github.com/ajorpheus/vagrant-ubuntu-oracle-xe setup.sql 作为 oracle 模块的 init.pp 的一部分运行(查看该文件的末尾附近或搜索“oracle-script”)。
我在运行这个 vagrant build 时遇到了一个错误,只是被告知“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 脚本也会失败。
我正在运行以下命令
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 必须是幂等的。但是,问题仍然存在,如果表空间已经存在,为什么 puppet 构建不会失败?
谢谢!
更新
添加 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
【问题讨论】:
-
根据调试输出,即使出现错误,sqlplus 似乎也返回“执行成功”。这里的问题是 sqlplus 报告成功。