Version information
This version is compatible with:
- Puppet Enterprise 2017.2.x, 2017.1.x, 2016.5.x, 2016.4.x
- Puppet >=3.4.0 <5.0.0
- , , ,
Start using this module
Add this module to your Puppetfile:
mod 'willdurand-nodejs', '2.0.0'
Learn more about managing modules with a PuppetfileDocumentation
puppet-nodejs
This module allows you to install Node.js and NPM. This module is published on the Puppet Forge as willdurand/nodejs.
Version 1.9
The 1.x branch will be EOLed two months after 2.0
is released.
If you need the docs for 1.x, see 1.9.
Installation
Manual installation
This modules depends on puppetlabs/stdlib and puppetlabs/gcc. So all repositories have to be checked out:
git clone git://github.com/willdurand/puppet-nodejs.git modules/nodejs
git clone git://github.com/puppetlabs/puppetlabs-stdlib.git modules/stdlib
git clone git://github.com/puppetlabs/puppetlabs-gcc.git modules/gcc
For Redhat based OS, the following are (typical) additional requirements:
git clone git://github.com/treydock/puppet-gpg_key.git modules/gpg_key
Puppet Module Tool:
puppet module install willdurand/nodejs
Librarian-puppet:
mod 'willdurand/nodejs', '2.x.x'
Usage
There are a few ways to use this puppet module. The easiest one is just using the class definition:
class { 'nodejs':
version => 'v6.0.0',
}
This install the precompiled Node.js version v6.0.0
on your machine. node
and npm
will be available in your $PATH
at /usr/local/bin
so you can just start using node
.
Shortcuts are provided to easily install the latest
release or the latest LTS release (lts
) by setting the version
parameter to latest
or lts
. It will automatically look for the last release available on https://nodejs.org.
# installs the latest nodejs version
class { 'nodejs':
version => 'latest',
}
# installs the latest nodejs LTS version
class { 'nodejs':
version => 'lts',
}
Compiling from source
In order to compile from source with gcc
, the make_install
must be true
.
class { 'nodejs':
version => 'lts',
make_install => true,
}
Setup using a generic version
Instead of fixing one specific nodejs version it's also possible to tell this module whether to use the latest of a certain minor release:
class { '::nodejs':
version => '6.3',
}
This will install the latest patch release of 6.3.x
.
The same is possible with major releases:
class { '::nodejs':
version => '6.x',
}
This will install the latest 6.x
release.
Setup with a given download timeout
Due to infrastructures with slower connections the download of the nodejs binaries should be configurable:
class { '::nodejs':
download_timeout => 0,
}
Setup multiple versions of Node.js
If you need more than one installed version of Node.js on your machine, you can just configure them using the instances
list.
class { '::nodejs':
version => 'v6.0.0',
instances => {
"node-v6" => {
version => 'v6.0.0'
},
"node-v5" => {
version => 'v5.0.0'
}
},
}
This will install the node version v5.0.0
and v6.0.0
on your machine with v6.0.0
as default and v5.0.0
as versioned binary in /usr/local/bin
:
/usr/local/bin/node # v6.0.0
/usr/local/bin/node-v6.0.0
/usr/local/bin/npm-v6.0.0
/usr/local/bin/npm # NPM shipped with v6.0.0
/usr/local/bin/npm-v5.0.0
/usr/local/bin/npm-v5.0.0
It is also possible to remove those versions again:
class { '::nodejs':
# ...
instances_to_remove => ['5.4'],
}
After the run the directory /usr/local/node/node-v5.4.1 has been purged. The link /usr/local/bin/node-v5.4.1 is also purged.
Note: It is not possible to install and uninstall an instance in the same run. The version defined in the version
parameter of the nodejs
class can't be removed in the same run. If a version should be removed, it must not be present in the instances
list.
Setup using custom amount of cpu cores
By default, all available cpu (that are detected using the ::processorcount
fact) cores are being used to compile nodejs. Set cpu_cores
to any number of cores you want to use.
class { 'nodejs':
version => 'lts',
cpu_cores => 2,
}
Configuring $NODE_PATH
The environment variable $NODE_PATH can be configured using the init
manifest:
class { '::nodejs':
version => 'lts',
node_path => '/your/custom/node/path',
}
It is not possible to adjust a $NODE_PATH through ::nodejs::install
.
Binary path
node
and npm
are linked to /usr/local/bin
to be available in your system $PATH
by default. To link those binaries to e.g /bin
, just set the parameter target_dir
.
class { 'nodejs':
version => 'lts',
target_dir => '/bin',
}
NPM
Also, this module installs NPM by default.
NPM Provider
This module adds a new provider: npm
. You can use it as usual:
package { 'express':
provider => npm
}
Note: When deploying a new machine without nodejs already installed, your npm package definition requires the nodejs class:
class { 'nodejs':
version => 'lts'
}
package { 'express':
provider => 'npm',
require => Class['nodejs']
}
NPM installer
The nodejs installer can be used if a npm package should not be installed globally, but in a certain directory.
There are two approaches how to use this feature:
Installing a single package into a directory
::nodejs::npm { 'npm-webpack':
ensure => present, # absent would uninstall this package
pkg_name => 'webpack',
version => 'x.x', # optional
options => '-x -y -z', # CLI options passed to the "npm install" cmd, optional
exec_user => 'vagrant', # exec user, optional
directory => '/target/directory', # target directory
home_dir => '/home/vagrant', # home directory of the user which runs the installation (vagrant in this case)
}
This would install the package webpack
into /target/directory
with version x.x
.
Executing a package.json
file
::nodejs::npm { 'npm-install-dir':
list => true, # flag to tell puppet to execute the package.json file
directory => '/target',
exec_user => 'vagrant',
options => '-x -y -z',
}
Proxy
When your puppet agent is behind a web proxy, export the http_proxy
environment variable:
export http_proxy=http://myHttpProxy:8888
Skipping package setup
As discussed in willdurand/composer#44 each module should get a build_deps
parameter which can be used in edge cases in order to turn the package setup of this module off:
class { '::nodejs':
build_deps => false,
}
In this case you'll need to take care of the following packages:
tar
ruby
wget
semver
(GEM used by ruby)make
(ifmake_install
=true
)gcc
compiler (ifmake_install
=true
)
Development with nix
If you're using nix
as dependency manager, you can create a custom shell which contains all dependencies declared in Gemfile.lock
by running nix-shell
in the root directory.
Running the tests
Install the dependencies using Bundler:
bundle install
Run the following command:
bundle exec rake test
Authors
- William Durand william.durand1@gmail.com
- Johannes Graf (@grafjo)
- Maximilian Bosch (@Ma27)
License
puppet-nodejs is released under the MIT License. See the bundled LICENSE file for details.
2.0.0
Version/Requirement changes
- dropped support for Node.js versions until
v0.12.0
- dropped support for all Puppet versions below
v3.4
- dropped support for all ruby versions below
v2.1
Code changes
Minor changes
-
removed the
::nodejs_latest_version
and::nodejs_stable_version
fact and replaced them with a puppet function to avoid evaluations on each node -
removed
with_npm
parameter (only used for Node.js 0.6 and below) -
fixed bug #94
-
added
cpu_cores
option to speedup the compilation process -
changed all downloads from
http
tohttps
-
remove installation of
git
package. -
added support for ARM architecture (
armv6l
andarmv7l
). -
added
download_timeout
parameter to simplify configuration of package download timeouts. -
dropped
profile.d
script to patch NodeJS paths. Target directory will be set withnodejs::$target_dir
which should be in$PATH
. See bcfdda3341aa8b0d885b40e9a6ab7f90859f9f3e and #177 for further reference.
Installer Refactoring
- added
puppetlabs-gcc
for package handling of the compiler (and removed custom implementation) - killed the
python_package
option (not needed anymore) nodejs::install
has been replaced by an internal API. to use multiple instances, use theinstances
andinstances_to_remove
option of thenodejs
class (see the docs for more details)- Introduced a new
build_deps
parameter which makes the entire package setup optional (seewilldurand/composer#44
).
Version refactoring
The whole version detection logic was quite outdated and needed a refactoring:
- removed the
stable
flag for versions. The behavior oflatest
was equal. - introduced the
lts
flag to fetch the latest LTS release of Node.js. - generic versions:
7.x
to fetch the latest release of the Node.js v7 branch.7.0
to fetch the latest7.0.x
release.
nodejs::npm
refactoring
The nodejs::npm
resource has been refactored in order to keep the logic inside maintainable.
The following breaking changes were made:
- Removed
install_opt
andremove_opt
and replaced it with a singleoptions
parameter. - Renamed
exec_as_user
toexec_user
as it's describes the intent of the parameter in a better way. - Dropped automatic generation of a home directory for the
npm
calls and added ahome_dir
parameter which does the job. - Removed the ability to write
dir:pkg
as resource title. - The
pkg_name
has now$title
as default parameter.
Dependencies
- puppetlabs/stdlib (>=3.2.1)
- puppetlabs/gcc (>=0.3.0)
Copyright (c) William Durand <will+git@drnd.me>, Johannes Graf, Maximilian Bosch Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.