
Question:
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 (<a href="https://github.com/mgutz/execSync" rel="nofollow">https://github.com/mgutz/execSync</a>). 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 (<a href="https://github.com/puppetlabs/puppetlabs-nodejs" rel="nofollow">https://github.com/puppetlabs/puppetlabs-nodejs</a>) 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?
<strong>Edited:</strong>
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.
Answer1: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'],
}
Answer2: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.