darkwizard242.nodejs

Ansible Role: nodejs

This role installs (by default) the nodejs package or uninstalls it (if specified) on Debian and EL-based systems. Node.js is a JavaScript runtime environment. npm and npx are also installed as part of this role. The default Node.js version installed is 18.x, unless you specifically request a different version.

Requirements

None.

Role Variables

Here are the available variables (found in defaults/main.yml):

Variables List:

nodejs_app: nodejs
nodejs_app_desired_state: present
nodejs_version: 18.x

# Debian requirements
nodejs_debian_pre_reqs:
  - apt-transport-https
  - gnupg
nodejs_debian_pre_reqs_desired_state: present
nodejs_repo_debian_gpg_key: https://deb.nodesource.com/gpgkey/nodesource.gpg.key
nodejs_repo_debian: "deb https://deb.nodesource.com/node_{{ nodejs_version }} {{ ansible_lsb['codename'] }} main"
nodejs_repo_debian_filename: "{{ nodejs_app }}"
nodejs_repo_debian_desired_state: present

# EL requirements
nodejs_repo_el: "https://rpm.nodesource.com/pub_{{ nodejs_version }}/el/{{ ansible_distribution_major_version }}/$basearch"
nodejs_repo_el_name: nodesource
nodejs_repo_el_description: Node.js EL Family Repo
nodejs_repo_el_gpgkey: https://rpm.nodesource.com/pub/el/NODESOURCE-GPG-SIGNING-KEY-EL
nodejs_repo_el_gpgcheck: yes
nodejs_repo_el_enabled: yes
nodejs_repo_el_filename: "{{ nodejs_app }}"
nodejs_repo_el_desired_state: present

Variables Table:

Variable Description
nodejs_app Name of the Node.js package to install, for example, nodejs.
nodejs_app_desired_state The state of the nodejs_app package. Options include install, check if available, or uninstall (values: present, latest, absent).
nodejs_version The version of Node.js to install.
nodejs_debian_pre_reqs Two recommended packages for Debian systems.
nodejs_debian_pre_reqs_desired_state Desired state for Node.js prerequisite apps on Debian.
nodejs_repo_debian_gpg_key GPG key needed for Debian systems.
nodejs_repo_debian Node.js repository URL for Debian systems, using ansible_lsb['codename'].
nodejs_repo_debian_filename Name of the repo file in /etc/apt/sources.list.d/ on Debian systems.
nodejs_repo_debian_desired_state present means create the repo file if it doesn't exist. absent is not recommended as it will block Node.js installation.
nodejs_repo_el Repository URL for Node.js on EL systems, using the major version of the distribution.
nodejs_repo_el_name Name of the Node.js repository on EL systems.
nodejs_repo_el_description Description for the Node.js repo file on EL systems.
nodejs_repo_el_gpgkey GPG key needed for EL systems.
nodejs_repo_el_gpgcheck Indicates if GPG check should be performed on EL systems.
nodejs_repo_el_enabled Set to enable the Node.js repository on EL systems.
nodejs_repo_el_filename Name of the repo file in /yum/sources.list.d/nodejs.repo on EL systems.
nodejs_repo_el_desired_state present means create the repo file if it doesn't exist. absent is not recommended as it will block Node.js installation.

Dependencies

None.

Example Playbook

For the default behavior of the role (i.e., installing the nodejs package) in Ansible playbooks:

- hosts: servers
  roles:
    - darkwizard242.nodejs

To customize the behavior of the role (e.g., installing version 14.x of Node.js):

- hosts: servers
  roles:
    - darkwizard242.nodejs
  vars:
    nodejs_version: 14.x

To customize the behavior of the role (e.g., uninstalling the nodejs package):

- hosts: servers
  roles:
    - darkwizard242.nodejs
  vars:
    nodejs_app_desired_state: absent

License

MIT

Author Information

This role was created by Ali Muhammad.

Informazioni sul progetto

Installs/Uninstalls 'nodejs'. A JavaScript runtime environment.

Installa
ansible-galaxy install darkwizard242.nodejs
Licenza
mit
Download
4k
Proprietario
Senior DevOps/CloudOps Engineer. Dedicated to Automating everything I come across. Love to work on and learn new technologies/tools everyday!