marverix.nodejs

Ansible Role: Node.js

Build Status Ansible Quality Score Ansible Role License: ISC

This Ansible role helps you install Node.js and npm on Linux. It can also set some basic npm settings.

Features

  • ✔️ Installs Node.js
    • You can choose which version to install
    • Makes sure the latest version of npm is installed
  • ✔️ Configures npm
    • Sets the global registry for a user
    • Sets the prefix for a user
    • Sets a default scope for a user
    • Configures scopes for a user
  • ✔️ Installs any global npm packages you want
  • ✔️ Ensures the nodejs alias is available
  • ✔️ Tested with Molecule Verify

Supported Platforms

  • ✔️ Ubuntu 16.04 (Xenial)
  • ✔️ Ubuntu 18.04 (Bionic)
  • ✔️ Ubuntu 20.04 (Focal)
  • ✔️ CentOS 7
  • ✔️ CentOS 8

Requirements

None

Role Variables

Variable Description Default Value
nodejs_version Version of Node.js to install 14
nodejs_npm_install_globally List of npm packages to install globally []
nodejs_npm_config List of npm configurations - See the section How to configure npm []

How to configure npm

nodejs_npm_config should be an array of objects. Each object should look like this:

Property Description Required
user User (one npm config per user) Yes
prefix npm prefix No
registry npm registry URL No
scopes List of scopes. Each scope must have name (without @) and registry. No
default_scope Default scope No

Dependencies

None

Example Playbook

  1. The simplest playbook

    ---
    - hosts: all
      roles:
        - marverix.nodejs
    
  2. Install mocha and eslint globally

    ---
    - hosts: all
      roles:
        - role: marverix.nodejs
          vars:
            nodejs_npm_install_globally:
              - mocha
              - eslint
    
  3. Set npm registry for user root, set prefix, configure scopes, and set default scope:

    ---
    - hosts: all
      roles:
        - role: marverix.nodejs
          vars:
            nodejs_npm_config:
              - user: root
                prefix: /home/root/.node
                registry: https://nexus.example.org/repository/npm/
                scopes:
                  - name: example-int
                    registry: https://nexus.example.org/repository/npm-int/
                  - name: example2-int
                    registry: https://nexus.example2.org/repository/npm-int/
                default_scope: example-int
    

    You can find a good blog post about setting up Nexus as your npm registry here: https://blog.sonatype.com/using-nexus-3-as-your-repository-part-2-npm-packages

License

ISC

Informazioni sul progetto

Ansible role that installs Node.js and configures npm

Installa
ansible-galaxy install marverix.nodejs
Licenza
isc
Download
189
Proprietario
Everyday normal Software Engineer