andrelohmann.nodesource

nodesource

Last test

Overview

This role helps you install Node.js from the nodesource repository on your Ubuntu server.

Requirements

You need to be using Ubuntu.

Role Variables

The main variable to set is the Node.js version. You can change it in group_vars/host_vars:

nodesource_nodejs_version: '20'

Example Playbook

To use this role, your playbook might look like this:

- hosts: nodesource
  roles:
     - { role: andrelohmann.nodesource }

Role Development

Special Features

This repository includes tools for role development like:

  • Code style checks (yamllint)
  • Ansible code checks (ansible-lint)
  • Testing with Molecule
  • GitHub Actions for automatic testing
  • Automatic version updates
  • Updating Ansible Galaxy
  • Displaying build status
  • Testing within Vagrant
  • Testing with Docker
  • Developing in Visual Studio Code

Prerequisites

For more info, visit: https://thedatabaseme.de/2022/01/17/automated-testing-your-ansible-role-with-molecule-and-github-actions/

  • Install Virtualbox and Vagrant (needed if testing with Vagrant)
  • Install Docker Desktop
  • Install Visual Studio Code with remote extension pack (dependencies in .vscode/extensions.json)

Development Setup

This role is developed using Molecule for testing, mainly in Visual Studio Code with a development container that includes all necessary tools (like Ansible and linters).

Tests will run on three Ubuntu versions: Bionic, Focal, and Jammy.

To run Molecule test containers from the development container, you need to mount the Docker socket into it.

Important Folders and Files

.devcontainer
  • Contains the Dockerfile for the development container
  • Configures how the development container starts (like mounting the Docker socket)
molecule/default/Dockerfile.js
  • Acts as a template for different platforms in molecule/default/molecule.yml
  • Sets up environments for systemd services (necessary for some roles)
  • Installs requirements to run Ansible in the container
  • Matches attributes in molecule/default/molecule.yml
  • Refer to the Molecule documentation for more details

Usage

Visual Studio Code

  1. Go to the root of your role and start VS Code:
code .
  1. In the development container, you can run these commands:
yamllint .
ansible-lint .
molecule create
molecule test

Vagrant + Virtualbox

  1. Change to your role's root directory.
  2. Go to the Vagrant folder.
  3. Start and enter the Vagrant machine:
vagrant up
vagrant ssh
  1. Navigate to your role folder:
cd /etc/ansible/roles/ansible-role-[tab]
  1. Run all tests:
yamllint .
ansible-lint .
molecule create
molecule test

Build and Release Process

This Ansible role has several GitHub workflows for testing and managing releases.

To manage releases, you need some settings:

Protecting the Main Branch

  1. Go to Settings -> Branches -> Add branch protection rule
  2. Set branch pattern name to main or master
  3. Check "Require a pull request before merging"
  4. Handle "Require approvals" as necessary

Grant Read and Write Permissions to GITHUB_TOKEN

  1. Go to Settings -> Actions -> General -> Workflow permissions -> select read and write permissions

Commit Messages Format

Follow this format for commit messages to indicate patch, minor, or major updates:

Patch (0.0.x)
fix(single_word): description
Minor (0.x.0)
feat(single_word): description
Major (x.0.0)
perf(single_word): description
BREAKING CHANGE: description of the breaking change

Make sure "BREAKING CHANGE: " is on a new line for major updates.

Add GALAXY_API_KEY Secret

  1. Log in to your GitHub account at https://galaxy.ansible.com/.
  2. Get the API key from Preferences -> API Key.
  3. Go to your GitHub repository.
  4. Navigate to Settings -> Secrets and variables -> Actions -> New repository secret.
  5. Use "GALAXY_API_KEY" as the key and paste the API key as the value.

License

MIT

Author Information

© Andre Lohmann (and others) 2023

GitHub Profile

Maintainer Contact

  • Andre Lohmann <lohmann.andre (at) gmail (dot) com>
Informazioni sul progetto

ansible galaxy role to install nodejs from nodesource

Installa
ansible-galaxy install andrelohmann.nodesource
Licenza
mit
Download
8.5k
Proprietario