Files
ArchiveBox/archivebox/plugantic/ansible/roles/setup_lib_npm/tasks/main.yml
2024-09-21 04:12:33 -07:00

100 lines
2.9 KiB
YAML
Executable File

---
- name: Make sure lib folders exist
file:
path: '{{item}}'
state: directory
recurse: true
loop:
- '{{LIB_DIR_NPM_BIN}}'
- '{{LIB_DIR_BIN}}'
###################################################################################
- name: Ensure dependencies are present.
when: ansible_facts['os_family']|lower == 'debian'
ansible.builtin.apt:
name:
- apt-transport-https
- python3-debian
- gnupg2
state: present
- name: Download NodeSource's signing key.
# NodeSource's web server discriminates the User-Agent used by the deb822_repository module.
# https://github.com/nodesource/distributions/issues/1723
when: ansible_facts['os_family']|lower == 'debian'
ansible.builtin.get_url:
url: https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key
dest: /etc/apt/signing-key-nodesource-repo.asc
owner: root
group: root
mode: '0444'
register: node_signing_key
- name: Add NodeSource repositories for Node.js.
when: ansible_facts['os_family']|lower == 'debian'
ansible.builtin.deb822_repository:
name: nodesource_{{ TARGET_NODE_VERSION }}
uris: "https://deb.nodesource.com/node_{{ TARGET_NODE_VERSION }}.x"
types: deb
suites: nodistro
components: main
signed_by: "{{ node_signing_key.dest }}"
state: present
register: node_repo
- name: Update apt cache if repo was added.
ansible.builtin.apt: update_cache=yes
when: ansible_facts['os_family']|lower == 'debian' and node_repo is changed
- name: Ensure Node.js and npm are installed.
when: ansible_facts['os_family']|lower == 'debian'
ansible.builtin.apt:
name: "nodejs={{ TARGET_NODE_VERSION | regex_replace('x', '') }}*"
state: present
- name: Load NPM and Node binaries
include_role:
name: load_binary
vars:
name: '{{item}}'
loop:
- node
- npm
- name: Check that installed Node version matches expected version
assert:
that:
- BINARIES.node.version is version(MIN_NODE_VERSION, '>=')
- BINARIES.npm.version is version(MIN_NPM_VERSION, '>=')
quiet: true
###################################################################################
# - name: "Install npm packages: {{install_npm}}"
# community.general.npm:
# name: '{{item}}'
# state: "{{state}}"
# path: '{{LIB_DIR_NPM}}'
# loop: "{{install_npm|dictsort|map(attribute='1')|map(attribute='packages')|flatten}}"
###################################################################################
###################################################################################
- set_fact:
NODE_BINPROVIDERS:
npm:
installer_abspath: "{{BINARIES.npm.abspath}}"
installer_version: "{{BINARIES.npm.version}}"
PATH: "{{LIB_DIR_NPM_BIN}}"
lib_dir_npm: "{{LIB_DIR_NPM}}"
- set_fact:
BINPROVIDERS: "{{ BINPROVIDERS | default({}) | combine(NODE_BINPROVIDERS) }}"
cacheable: true
- debug:
msg: "{{ {'BINARIES': BINARIES, 'BINPROVIDERS': BINPROVIDERS} }}"