andrelohmann.nodesource
nodesource
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
- Go to the root of your role and start VS Code:
code .
- In the development container, you can run these commands:
yamllint .
ansible-lint .
molecule create
molecule test
Vagrant + Virtualbox
- Change to your role's root directory.
- Go to the Vagrant folder.
- Start and enter the Vagrant machine:
vagrant up
vagrant ssh
- Navigate to your role folder:
cd /etc/ansible/roles/ansible-role-[tab]
- 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
- Go to Settings -> Branches -> Add branch protection rule
- Set branch pattern name to
main
ormaster
- Check "Require a pull request before merging"
- Handle "Require approvals" as necessary
Grant Read and Write Permissions to GITHUB_TOKEN
- 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
- Log in to your GitHub account at https://galaxy.ansible.com/.
- Get the API key from Preferences -> API Key.
- Go to your GitHub repository.
- Navigate to Settings -> Secrets and variables -> Actions -> New repository secret.
- Use "GALAXY_API_KEY" as the key and paste the API key as the value.
License
MIT
Author Information
© Andre Lohmann (and others) 2023
Maintainer Contact
- Andre Lohmann <lohmann.andre (at) gmail (dot) com>
ansible-galaxy install andrelohmann.nodesource