deluxebrain.ansible_role_nodejs

Role Name: NODEJS

Build Status

This is a NodeJS installer for Linux. It comes with node-build and nodenv-vars plugins by default, which help to install different versions of Node.js and set project-specific environment variables.

Requirements

No special requirements.

Role Variables

You can find all the variables in defaults/main.yml. You can also change these variables in your playbook.

  • nodenv_version: (default: latest)
    The version of nodenv to install.

  • nodebuild_version: (default: latest)
    The version of node-build to install.

  • nodenvvars_version: (default: latest)
    The version of nodenv-vars to install.

  • init_shell: (default: yes)
    Whether to configure the shell to load nodenv.

  • global_nodejs_version: (default: "")
    The default version of Node.js to use.

  • nodejs_versions: (default: [])
    A list of Node.js versions to install.

  • plugins: (default: [])
    A list of plugins to install, specified with:

    • name: Name of the plugin
    • repo: GitHub repository of the plugin
    • version: Plugin version, use "latest" for the newest version.

Dependencies

No dependencies.

Example Playbook

Here is an example to install specific versions of nodenv, a specific version of Node.js, and the nodenv-default-packages plugin:

- hosts: servers
  roles:
      - deluxebrain.python
        nodenv_version: 1.3.1
        global_nodejs_version: 12.3.1
        nodenv_versions:
            - 12.3.1
        plugins:
          - name: nodenv-default-packages
            repo: https://github.com/nodenv/nodenv-default-packages.git
            version: latest

Development Installation

Packages are divided between development and production dependencies, managed in requirements-dev.txt and requirements.txt.

Production packages use pip-tools to handle project dependencies via requirements.in.

# Create a virtual environment for the project
# Install development dependencies in the virtual environment
make install

pip-tools generates a fixed requirements.txt file for both syncing the Python virtual environment and for production packages.

Do not edit requirements.txt directly; regenerate it every time you change requirements.in like this, which will also sync package changes:

# Convert requirements.in to requirements.txt
# Install packages from requirements.txt into the virtual environment
make sync

pip-tools and other development requirements are installed from requirements-dev.txt.

Role Usage

NodeJS versions are managed using nodenv.

nodenv lets you run different Node versions on your machine.

# Install a specific Node version
nodenv install 12.3.1

# Create and enter a project directory
mkdir ~/my-project && cd $_

# Set the project to use a specific Node version
nodenv local 12.3.1   # This creates a .node-version file

Package Management with npm

You can use npm to create a new project, as shown below:

npx license mit > LICENSE     # Generate a license file
npx gitignore node            # Create a .gitignore file
npx covgen <EMAIL_ADDRESS>    # Set up Code of Conduct contact email
npm init -y                   # Initialize a new project
npm install <package>         # Install a specific package

It's better to use npx instead of installing packages globally.

Other Tools

nodenv-vars

nodenv-vars is a plugin for managing environment variables specific to each project.

Here's how to use it:

echo FOO=BAR >> .nodenv-vars  # Set an environment variable
$ nodenv vars                   # See the active environment variables
export FOO='BAR'               # Exports the variable

License

MIT / BSD

Author Information

This role was created in 2020 by deluxebrain.

Informazioni sul progetto

Node.js installer for Linux

Installa
ansible-galaxy install deluxebrain.ansible_role_nodejs
Licenza
mit
Download
752
Proprietario