-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 0b2304c
Showing
19 changed files
with
363 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
use_default_rules: true | ||
|
||
skip_list: | ||
- yaml | ||
- role-name | ||
|
||
exclude_paths: | ||
- .cache | ||
- .github | ||
- requirements.yml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
--- | ||
name: Code linting with ansible-lint | ||
|
||
on: | ||
pull_request: | ||
push: | ||
branches: | ||
- main | ||
|
||
jobs: | ||
precheck-role-lint: | ||
name: Lint | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout the current branch | ||
uses: actions/checkout@main | ||
|
||
- name: Run ansible-lint linting command | ||
uses: ansible/ansible-lint@main |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
--- | ||
name: Run role tests using Molecule | ||
|
||
on: | ||
pull_request: | ||
push: | ||
branches: | ||
- main | ||
|
||
schedule: | ||
- cron: "7 4 4 * *" | ||
|
||
jobs: | ||
precheck-role-molecule-test: | ||
name: Build test instance | ||
runs-on: ubuntu-latest | ||
strategy: | ||
matrix: | ||
include: | ||
- distro: ubuntu2404 | ||
playbook: converge.yml | ||
- distro: ubuntu2204 | ||
playbook: converge.yml | ||
|
||
steps: | ||
- name: Checkout the current branch | ||
uses: actions/checkout@main | ||
|
||
- name: Setup of Python 3 | ||
uses: actions/setup-python@main | ||
with: | ||
python-version: "3.x" | ||
|
||
- name: Install Ansible dependencies | ||
run: pip3 install ansible molecule molecule-plugins[docker] docker | ||
|
||
- name: Run Molecule test commands | ||
run: molecule test | ||
env: | ||
MOLECULE_DISTRO: ${{ matrix.distro }} | ||
MOLECULE_PLAYBOOK: ${{ matrix.playbook }} | ||
PY_COLORS: "1" | ||
ANSIBLE_FORCE_COLOR: "1" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# Ansible files | ||
|
||
*.retry | ||
|
||
# Environment variables | ||
|
||
*.env | ||
!.env-* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) ansible-role-nvm | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
# ansible-role-nvm | ||
|
||
A role for [Ansible](https://github.com/ansible/ansible), that installs [Node Version Manager](https://github.com/nvm-sh/nvm), along with [Node.js](https://github.com/nodejs). | ||
|
||
## Requirements | ||
|
||
This role does not need any additional required packages. | ||
|
||
## Quick start | ||
|
||
1. First clone this repository and add into your project directory. | ||
2. Include the role in your [Ansible](https://github.com/ansible/ansible) playbook. | ||
|
||
## Example playbook | ||
|
||
Example use of a role, that will install the latest LTS version of [Node.js](https://github.com/nodejs). | ||
|
||
```yml | ||
- hosts: all | ||
roles: | ||
- role: krudi.nvm | ||
# This option adds block code that loads the configuration from the Node Version Manager | ||
# If you don't have any Node Version Manager loading from files such as **.bashrc**, **.zsh** or **.profile**, this option should be set to **true**. | ||
nvm_nodejs_add_block: false | ||
|
||
- role: krudi.nvm | ||
nodejs: | ||
install: true | ||
version: 22 | ||
nvm: | ||
install: true | ||
add_block: true | ||
``` | ||
## Additional information | ||
To change the version of Node Version Manager after installing this role, just use the official [Node Version Manager](https://github.com/nvm-sh/nvm) install command. | ||
More information can be found here: <https://github.com/nvm-sh/nvm#usage>. | ||
## Issue | ||
Have you found a bug in this project or have a suggestion for a new feature? Create a new ticket for the bug or feature, which can be found on the [GitHub](https://github.com/krudi/ansible-role-nvm/issues) page. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
--- | ||
nodejs: | ||
install: true | ||
version: 22 | ||
|
||
nvm: | ||
install: true | ||
script: https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | ||
# This option adds block code that loads the configuration from the Node Version Manager. | ||
# If you don't have any Node Version Manager loading from files such as .bashrc, .zsh or .profile, this option should be set to true | ||
add_block: false |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
--- | ||
- name: Reload shell | ||
ansible.builtin.command: /bin/bash -c "source ~/.bashrc" | ||
changed_when: false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
--- | ||
galaxy_info: | ||
role_name: nvm | ||
description: A role for Ansible that installs Node Version Manager, along with Node.js. | ||
license: MIT | ||
min_ansible_version: "2.9" | ||
author: krudi | ||
standalone: true | ||
platforms: | ||
- name: Ubuntu | ||
versions: | ||
- jammy | ||
- noble | ||
|
||
galaxy_tags: | ||
- nodejs | ||
- node | ||
- nvm | ||
|
||
dependencies: [] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
--- | ||
- name: Converge | ||
hosts: all | ||
|
||
pre_tasks: | ||
- name: Ensure APT package cache is updated | ||
ansible.builtin.apt: | ||
upgrade: yes | ||
update_cache: true | ||
cache_valid_time: 86400 | ||
|
||
- name: Ensure required packages are installed | ||
ansible.builtin.package: | ||
name: "{{ dependency }}" | ||
state: present | ||
loop: "{{ nvm_dependencies }}" | ||
loop_control: | ||
loop_var: dependency | ||
|
||
roles: | ||
- role: "{{ lookup('env', 'MOLECULE_PROJECT_DIRECTORY') | basename }}" | ||
nodejs: | ||
install: true | ||
version: 22 | ||
nvm: | ||
install: true | ||
script: https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | ||
add_block: false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
--- | ||
driver: | ||
name: docker | ||
|
||
dependency: | ||
name: galaxy | ||
options: | ||
ignore-errors: true | ||
ignore-certs: true | ||
|
||
platforms: | ||
- name: instance-ubuntu2404 | ||
image: "geerlingguy/docker-${MOLECULE_DISTRO:-ubuntu2404}-ansible:latest" | ||
command: ${MOLECULE_DOCKER_COMMAND:-""} | ||
volumes: | ||
- /sys/fs/cgroup:/sys/fs/cgroup:rw | ||
privileged: true | ||
pre_build_image: true | ||
cgroupns_mode: host | ||
|
||
- name: instance-ubuntu2004 | ||
image: "geerlingguy/docker-${MOLECULE_DISTRO:-ubuntu2004}-ansible:latest" | ||
command: ${MOLECULE_DOCKER_COMMAND:-""} | ||
volumes: | ||
- /sys/fs/cgroup:/sys/fs/cgroup:rw | ||
privileged: true | ||
pre_build_image: true | ||
cgroupns_mode: host | ||
|
||
provisioner: | ||
name: ansible | ||
playbooks: | ||
converge: ${MOLECULE_PLAYBOOK:-converge.yml} | ||
|
||
verifier: | ||
name: ansible | ||
|
||
scenario: | ||
name: default | ||
test_sequence: | ||
- dependency | ||
- cleanup | ||
- destroy | ||
- syntax | ||
- create | ||
- prepare | ||
- converge | ||
- idempotence | ||
- side_effect | ||
- verify | ||
- cleanup | ||
- destroy |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
--- | ||
- name: Loading a task to install dependencies | ||
ansible.builtin.include_tasks: setup-dependencies.yml | ||
when: ansible_os_family == "Debian" | ||
|
||
- name: Loading a task to install Node.js | ||
ansible.builtin.include_tasks: setup-node.yml | ||
when: ansible_os_family == "Debian" | ||
|
||
- name: Loading a task to install Node Version Manager | ||
ansible.builtin.include_tasks: setup-nvm.yml | ||
when: ansible_os_family == "Debian" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
--- | ||
- name: Ensure APT package cache is updated | ||
ansible.builtin.apt: | ||
update_cache: true | ||
cache_valid_time: 600 | ||
|
||
- name: Install required dependencies | ||
become: true | ||
ansible.builtin.package: | ||
name: "{{ dependency }}" | ||
state: present | ||
loop: "{{ nvm_dependencies }}" | ||
loop_control: | ||
loop_var: dependency |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
--- | ||
- name: Ensure APT package cache is updated | ||
ansible.builtin.apt: | ||
update_cache: true | ||
cache_valid_time: 600 | ||
|
||
- name: Ensure the directory for storing APT keyrings exists and has the correct permissions | ||
ansible.builtin.file: | ||
path: /etc/apt/keyrings | ||
state: directory | ||
mode: "0755" | ||
when: nodejs.install | default(nodejs.install) | ||
|
||
- name: Download the GPG key for Node.js from the specified URL to a temporary location | ||
ansible.builtin.get_url: | ||
url: https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | ||
dest: /tmp/nodesource.gpg.key | ||
mode: "0644" | ||
when: nodejs.install | default(nodejs.install) | ||
|
||
- name: Convert the downloaded Node.js GPG key to a format suitable for APT and add it to the keyring directory | ||
ansible.builtin.command: > | ||
gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg /tmp/nodesource.gpg.key | ||
args: | ||
creates: /etc/apt/keyrings/nodesource.gpg | ||
when: nodejs.install | default(nodejs.install) | ||
|
||
- name: Ensure the Node.js GPG key in the keyring directory has the correct read permissions for all users | ||
ansible.builtin.file: | ||
path: /etc/apt/keyrings/nodesource.gpg | ||
mode: "0644" | ||
when: nodejs.install | default(nodejs.install) | ||
|
||
- name: Add the Node.js repository to APT, allowing Node.js packages to be installed and updated from it | ||
ansible.builtin.apt_repository: | ||
repo: "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_{{ nodejs.version }}.x nodistro main" | ||
state: present | ||
when: nodejs.install | default(nodejs.install) | ||
|
||
- name: Update the APT package list to include the latest information from all configured repositories, including Node.js | ||
ansible.builtin.apt: | ||
update_cache: yes | ||
when: nodejs.install | default(nodejs.install) | ||
|
||
- name: Install the Node.js package using APT | ||
ansible.builtin.apt: | ||
name: nodejs | ||
state: present | ||
when: nodejs.install | default(nodejs.install) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
--- | ||
- name: Install Node Version Manager | ||
Check failure on line 2 in tasks/setup-nvm.yml GitHub Actions / Lintcommand-instead-of-module
|
||
ansible.builtin.shell: > | ||
curl -o- {{ nvm.script }} | bash | ||
args: | ||
executable: /bin/bash | ||
creates: "~/.nvm/nvm.sh" | ||
when: nvm.install | default(nvm.install) | ||
|
||
- name: Ensure .bashrc file exists in the user home directory | ||
ansible.builtin.file: | ||
path: "~/.bashrc" | ||
state: touch | ||
mode: "0755" | ||
|
||
- name: Add Node Version Manager initialization to .bashrc file for the user | ||
ansible.builtin.blockinfile: | ||
path: "~/.bashrc" | ||
block: | | ||
export NVM_DIR="/usr/local/nvm" | ||
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" | ||
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" | ||
when: nvm.install | default(nvm.install) and nvm.add_block | default(nvm.add_block) | ||
notify: Reload shell |
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
nvm_dependencies: | ||
- apt-transport-https | ||
- gnupg2 | ||
- curl |