Installing execSync using Puppet

拥有回忆 提交于 2019-12-12 06:17:17

问题


I am writing a Puppet module to setup an application on our test servers. The testing environment requires us to install a node package called execSync (https://github.com/mgutz/execSync). Since execSync is a native package, it gets compiled on installation. When I try to manually install it on the server, it gets installed. However, when I do the same thing using Puppet, compilation step fails.

I have tried installing execSync using the puppetlabs-nodejs module (https://github.com/puppetlabs/puppetlabs-nodejs) and using exec defined type with command npm install execSync as well, and nothing seems to work. I have also checked that the right versions of nodejs and npm are used.

I would love to automate this process completely but nothing seems to work and I have run out of options. What could be the possible reasons?

Edited:

Here is the manifest I am using:

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,
}

I run this using puppet apply.

This is what I see in the console output:

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

The same thing works just fine when I run the command manually. The compilation happens successfully.


回答1:


Figured it out. I had been trying to understand what was different in the two. It seems that the environment was different. The compilation step requires the HOME env variable to be set. When it is not set, the compilation step fails without any helpful error messages.

Finally, ended up using the following manifest:

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'],
}



回答2:


Make sure to use fully qualified paths when doing an exec, something like:

exec {'install-execSync':
  command  => '/usr/local/bin/npm install execSync',
}

For automating the process completely with the puppetlabs module (which you want to do) we need more info.



来源:https://stackoverflow.com/questions/28878023/installing-execsync-using-puppet

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!