Puppet Class: psick::nodejs

Defined in:
manifests/nodejs.pp

Summary

This class manages nodejs either via system packages or via NVM

Overview

The class allows full management of nodejs

psick::nodejs::nvm_manage: true psick::nodejs::nvm_installs:

mastermonkey:
  node_instance_default: '8.12.0'
  npm_packages:
    yarn: {}
    pm2:
      version: 2.10.4

Examples:

Install a specific version of the package

psick::nodejs::ensure: '0.4.2'
psick::nodejs::package_manage: true

Remove all the resources managed by the class

psick::nodejs::ensure: 'absent'

Install nodejs via nvm for a given user. It’s defined the default nodejs version

and optionally a list on npm packages

Parameters:

  • ensure (String) (defaults to: 'present')

    If to install or remove the resources managed by this class. Can be present, absent, latest or a specific package version number

  • package_manage (Boolean) (defaults to: false)

    If to install the global nodejs rpm package.

  • package_name (String) (defaults to: 'nodejs')

    The name of the package to install

  • package_params (Hash) (defaults to: {})

    An hash of additional params to pass as arguments to the package resource. Use this for special needs.

  • setup_script_manage (Boolean) (defaults to: false)

    If to manage the download and execution of setup script for yum repo

  • setup_script_url (String) (defaults to: 'https://rpm.nodesource.com/setup_10.x')

    The url from where to download the setup script

  • setup_script_path (String) (defaults to: '/tmp/NodeJS')

    The path where to download the setup script.

  • setup_script_creates (String) (defaults to: '')

    A file created by the setup script (the yum repo)

  • nvm_manage (Boolean) (defaults to: false)

    If to manage the installation of jodejs via NVM (which is automatically installable for different users)

  • setup_script_params (Hash) (defaults to: {})
  • nvm_installs (Hash) (defaults to: {})


47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# File 'manifests/nodejs.pp', line 47

class psick::nodejs (

  String $ensure          = 'present',

  Boolean $package_manage = false,
  String $package_name    = 'nodejs',
  Hash $package_params    = {},

  Boolean $setup_script_manage = false,
  String $setup_script_url     = 'https://rpm.nodesource.com/setup_10.x',
  String $setup_script_path    = '/tmp/NodeJS',
  Hash $setup_script_params    = {},
  String $setup_script_creates = '', # lint:ignore:params_empty_string_assignment

  Boolean $nvm_manage          = false,
  Hash $nvm_installs           = {},
) {
  # Setup script management
  if $setup_script_manage {
    archive { $setup_script_path:
      ensure        => $ensure,
      source        => $setup_script_url,
      extract       => false,
      checksum_type => 'none',
      cleanup       => false,
      before        => Package[$package_name],
      notify        => Exec['nodejs setup'],
    }
    $setup_script_default_params = {
      command => "/bin/bash ${setup_script_path} > njs_setup.txt",
      creates => $setup_script_creates,
    }
    exec { 'nodejs setup':
      * => $setup_script_default_params + $setup_script_params,
    }
  }

  # Package management
  if $package_manage {
    $package_defaults = {
      ensure => $ensure,
    }
    package { $package_name:
      *      => $package_defaults + $package_params,
    }
  }

  $nvm_installs.each | $k,$v | {
    psick::nodejs::nvm { $k:
      * => $v,
    }
  }
}