Install nodejs, and use npm to install n for node version management.
This commit is contained in:
parent
6269782412
commit
e835992ef4
15
README.md
15
README.md
@ -1,9 +1,11 @@
|
|||||||
# Ansible Role: yarn
|
# Ansible Role: nodejs
|
||||||
|
|
||||||
Install yarn packages from the official yarn repositories.
|
Install nodejs, npm and yarn packages from the official yarn repositories. Optionally install n from npm repositories for version management.
|
||||||
|
|
||||||
Tested on:
|
Tested on:
|
||||||
|
|
||||||
|
* Archlinux
|
||||||
|
* Debian 11
|
||||||
* Ubuntu 22.04
|
* Ubuntu 22.04
|
||||||
|
|
||||||
## Requirements
|
## Requirements
|
||||||
@ -12,13 +14,18 @@ None.
|
|||||||
|
|
||||||
## Role Variables
|
## Role Variables
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
node_version: node_20.x
|
||||||
|
n_enabled: yes
|
||||||
|
```
|
||||||
|
|
||||||
See the role [vars](vars/main.yml)
|
See the role [vars](vars/main.yml)
|
||||||
|
|
||||||
## Example Playbook
|
## Example Playbook
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
- hosts: yarn
|
- hosts: nodejs
|
||||||
roles:
|
roles:
|
||||||
- role: bleetube.yarn
|
- role: bleetube.nodejs
|
||||||
become: true
|
become: true
|
||||||
```
|
```
|
3
defaults/main.yml
Normal file
3
defaults/main.yml
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
---
|
||||||
|
node_version: node_20.x
|
||||||
|
n_enabled: yes # https://github.com/tj/n
|
@ -1,12 +1,18 @@
|
|||||||
---
|
---
|
||||||
# https://www.jeffgeerling.com/blog/2022/aptkey-deprecated-debianubuntu-how-fix-ansible
|
# https://www.jeffgeerling.com/blog/2022/aptkey-deprecated-debianubuntu-how-fix-ansible
|
||||||
|
- name: Add nodesource apt repository key.
|
||||||
|
ansible.builtin.get_url:
|
||||||
|
url: "{{ nodesource_repo_key_url }}"
|
||||||
|
dest: /usr/share/keyrings/nodesource-archive.asc
|
||||||
|
mode: '0644'
|
||||||
|
|
||||||
- name: Add yarn apt repository key.
|
- name: Add yarn apt repository key.
|
||||||
ansible.builtin.get_url:
|
ansible.builtin.get_url:
|
||||||
url: "{{ yarn_repo_key_url }}"
|
url: "{{ yarn_repo_key_url }}"
|
||||||
dest: /usr/share/keyrings/yarn-archive.asc
|
dest: /usr/share/keyrings/yarn-archive.asc
|
||||||
mode: '0644'
|
mode: '0644'
|
||||||
|
|
||||||
- name: Ensure the repository is added with the relevant trusted GPG key
|
- name: Ensure the yarn repository is added with the relevant trusted GPG key
|
||||||
ansible.builtin.lineinfile:
|
ansible.builtin.lineinfile:
|
||||||
path: /etc/apt/sources.list.d/yarn.list
|
path: /etc/apt/sources.list.d/yarn.list
|
||||||
regexp: dl.yarnpkg.com
|
regexp: dl.yarnpkg.com
|
||||||
@ -14,13 +20,23 @@
|
|||||||
create: true
|
create: true
|
||||||
register: yarn_repo
|
register: yarn_repo
|
||||||
|
|
||||||
|
- name: Ensure the nodesource repository is added with the relevant trusted GPG key
|
||||||
|
ansible.builtin.lineinfile:
|
||||||
|
path: /etc/apt/sources.list.d/nodesource.list
|
||||||
|
regexp: deb.nodesource.com
|
||||||
|
line: "deb [arch=amd64 signed-by=/usr/share/keyrings/nodesource-archive.asc] https://deb.nodesource.com/{{ node_version }} {{ ansible_distribution_release }} main"
|
||||||
|
create: true
|
||||||
|
register: nodesource_repo
|
||||||
|
|
||||||
- name: Update the apt repository cache
|
- name: Update the apt repository cache
|
||||||
ansible.builtin.apt:
|
ansible.builtin.apt:
|
||||||
update_cache: yes
|
update_cache: yes
|
||||||
when: yarn_repo.changed
|
when: nodesource_repo.changed or yarn_repo.changed
|
||||||
|
|
||||||
- name: Install the yarn package
|
- name: Install the nodejs and yarn packages
|
||||||
ansible.builtin.apt:
|
ansible.builtin.apt:
|
||||||
name: yarn
|
name:
|
||||||
state: present
|
- nodejs
|
||||||
|
- yarn
|
||||||
|
state: latest
|
||||||
|
|
||||||
|
@ -1,10 +1,18 @@
|
|||||||
---
|
---
|
||||||
- name: Install yarn (Debian)
|
- name: Install npm and yarn (Debian)
|
||||||
import_tasks: Debian.yml
|
import_tasks: Debian.yml
|
||||||
when: ansible_os_family == 'Debian'
|
when: ansible_os_family == 'Debian'
|
||||||
|
|
||||||
- name: Install yarn (non-Debian)
|
- name: Install npm and yarn (non-Debian)
|
||||||
ansible.builtin.package:
|
ansible.builtin.package:
|
||||||
name: yarn
|
name:
|
||||||
|
- nodejs
|
||||||
|
- yarn
|
||||||
state: present
|
state: present
|
||||||
when: ansible_os_family != 'Debian'
|
when: ansible_os_family != 'Debian'
|
||||||
|
|
||||||
|
- name: Install 'n' package
|
||||||
|
ansible.builtin.npm:
|
||||||
|
name: n
|
||||||
|
global: yes
|
||||||
|
when: n_enabled
|
||||||
|
@ -1,2 +1,6 @@
|
|||||||
---
|
---
|
||||||
|
# Nodesource key ID: 9FD3B784BC1C6FC31A8A0A1C1655A0AB68576280
|
||||||
|
nodesource_repo_key_url: https://deb.nodesource.com/gpgkey/nodesource.gpg.key
|
||||||
|
|
||||||
|
# Yarn key ID: 72ECF46A56B4AD39C907BBB71646B01B86E50310
|
||||||
yarn_repo_key_url: https://dl.yarnpkg.com/debian/pubkey.gpg
|
yarn_repo_key_url: https://dl.yarnpkg.com/debian/pubkey.gpg
|
Loading…
Reference in New Issue
Block a user