geerlingguy.nodejs

Ansible Role: Node.js

CI

This role installs Node.js on RHEL/CentOS or Debian/Ubuntu systems.

Requirements

There are no special requirements.

Role Variables

Here are the available variables with their default values (see defaults/main.yml):

nodejs_version: "16.x"

This specifies the version of Node.js to install. The default is "14.x", which works on most supported operating systems. Other versions like "10.x", "14.x", "18.x", etc., should work on the latest Debian/Ubuntu and RHEL/CentOS.

nodejs_install_npm_user: "{{ ansible_ssh_user }}"

This is the user for whom npm packages will be installed. The default is ansible_user.

npm_config_prefix: "/usr/local/lib/npm"

This is the global directory for the installation. The nodejs_install_npm_user must have write access here.

npm_config_unsafe_perm: "false"

Set this to true to avoid switching user IDs when running package scripts. If it is set to false, installing as a non-root user will not work.

nodejs_npm_global_packages: []

This is a list of npm packages (with optional versions) to be installed globally. For example:

nodejs_npm_global_packages:
  - name: jslint
    version: 0.9.3
  - name: node-sass
  - node-sass
  - name: node-sass
    state: absent
nodejs_package_json_path: ""

You can set this to point to a specific package.json file (e.g., "/var/www/app/package.json"). It will install all defined packages using Ansible's npm module.

nodejs_generate_etc_profile: "true"

By default, this role will create the file /etc/profile.d/npm.sh with exported variables (PATH, NPM_CONFIG_PREFIX, NODE_PATH). If you want to avoid creating this file (e.g., for a non-global install), set it to "false".

Dependencies

No dependencies.

Example Playbook

- hosts: utility
  vars_files:
    - vars/main.yml
  roles:
    - geerlingguy.nodejs

Inside vars/main.yml:

nodejs_npm_global_packages:
  - name: jslint
  - name: node-sass

License

MIT / BSD

Author Information

This role was created in 2014 by Jeff Geerling, who is also the author of Ansible for DevOps.

Informazioni sul progetto

Node.js installation for Linux

Installa
ansible-galaxy install geerlingguy.nodejs
Licenza
mit
Download
3.3M
Proprietario
Father, author, developer, maker. Sometimes called "an inflammatory enigma". #stl #drupal #ansible #k8s #raspberrypi #crohns