我正在编写一个Puppet模块来在我们的测试服务器上设置应用程序。测试环境要求我们安装名为execSync(https://github.com/mgutz/execSync)的节点包。由于execSync是本机程序包,因此会在安装时进行编译。当我尝试在服务器上手动安装它时,它会被安装。但是,当我使用Puppet做同样的事情时,编译步骤失败。
我尝试使用puppetlabs-nodejs模块(https://github.com/puppetlabs/puppetlabs-nodejs)安装execSync,并使用命令exec
使用npm install execSync
定义类型,似乎没有任何效果。我还检查过使用了正确版本的nodejs和npm。
我希望完全自动化这个过程,但似乎没有任何工作,我已经没有选择了。可能的原因是什么?
编辑:
这是我正在使用的清单:
exec { 'npm-install':
command => 'npm install execSync',
cwd => '/var/www/appv3',
path => '/usr/local/node/node-default/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin',
logoutput => true,
}
我使用puppet apply
运行此功能。
这是我在控制台输出中看到的:
Notice: Compiled catalog for test.app.com in environment production in 0.54 seconds
Notice: /Stage[main]/Main/Exec[npm-install]/returns: npm http GET https://registry.npmjs.org/execSync
Notice: /Stage[main]/Main/Exec[npm-install]/returns: npm http 304 https://registry.npmjs.org/execSync
Notice: /Stage[main]/Main/Exec[npm-install]/returns: npm http GET https://registry.npmjs.org/temp
Notice: /Stage[main]/Main/Exec[npm-install]/returns: npm http 304 https://registry.npmjs.org/temp
Notice: /Stage[main]/Main/Exec[npm-install]/returns: npm http GET https://registry.npmjs.org/rimraf
Notice: /Stage[main]/Main/Exec[npm-install]/returns: npm http 304 https://registry.npmjs.org/rimraf
Notice: /Stage[main]/Main/Exec[npm-install]/returns: npm http GET https://registry.npmjs.org/graceful-fs
Notice: /Stage[main]/Main/Exec[npm-install]/returns: npm http 304 https://registry.npmjs.org/graceful-fs
Notice: /Stage[main]/Main/Exec[npm-install]/returns:
Notice: /Stage[main]/Main/Exec[npm-install]/returns: > execSync@1.0.2 install /var/www/appv3frontend_testapp.vwo.com/node_modules/execSync
Notice: /Stage[main]/Main/Exec[npm-install]/returns: > node install.js
Notice: /Stage[main]/Main/Exec[npm-install]/returns:
Notice: /Stage[main]/Main/Exec[npm-install]/returns: [execsync v1.0.2] Attempting to compile native extensions.
Notice: /Stage[main]/Main/Exec[npm-install]/returns: [execSync v1.0.2]
Notice: /Stage[main]/Main/Exec[npm-install]/returns: Native code compile failed!!
Notice: /Stage[main]/Main/Exec[npm-install]/returns: execSync@1.0.2 node_modules/execSync
Notice: /Stage[main]/Main/Exec[npm-install]/returns: └── temp@0.5.1 (rimraf@2.1.4)
Notice: /Stage[main]/Main/Exec[npm-install]/returns: executed successfully
当我手动运行命令时,同样的工作正常。编译成功。
答案 0 :(得分:2)
想出来。我一直试图了解两者的不同之处。似乎环境不同。编译步骤需要设置HOME
env变量。如果未设置,则编译步骤将失败,并且不会显示任何有用的错误消息。
最后,最后使用以下清单:
exec { 'npm-install':
command => 'npm install execSync',
cwd => '/var/www/appv3',
path => '/usr/local/node/node-default/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin',
environment => ['HOME=/root'],
}
答案 1 :(得分:0)
确保在执行exec时使用完全限定的路径,例如:
exec {'install-execSync':
command => '/usr/local/bin/npm install execSync',
}
为了完全使用puppetlabs模块(您想要做的)自动完成该过程,我们需要更多信息。