ArchiveBox/archivebox/playbooks/install_npm.yml
2024-09-17 00:48:47 -07:00

82 lines
2.5 KiB
YAML
Executable file

#!/usr/bin/env ansible-playbook
---
- import_playbook: install_package.yml
vars:
state: 'latest'
install_packages:
node:
bin_name: 'node'
packages: ['node']
when: BINARIES.node is not defined
- import_playbook: load_binaries.yml
vars:
load_binaries:
node: {bin_name: 'node', version_cmd: 'node --version'}
npm: {bin_name: 'npm', version_cmd: 'npm --version'}
when: BINARIES.npm is not defined
- name: "Install node, npm, and npx"
hosts: localhost
gather_facts: no
vars:
DATA_DIR: '/Volumes/NVME/Users/squash/Code/archiveboxes/archivebox7/data4'
LIB_DIR: '{{DATA_DIR}}/lib'
LIB_DIR_BIN: '{{LIB_DIR}}/bin'
LIB_DIR_NPM: '{{LIB_DIR}}/npm'
LIB_DIR_NPM_BIN: '{{LIB_DIR_NPM}}/node_modules/.bin'
MIN_NODE_VERSION: '20.0.0'
MIN_NPM_VERSION: '10.0.0'
state: 'present'
install_npm: {}
tasks:
# - package: update_cache=yes
# when: ansible_facts['os_family'] == "Debian"
- name: Make sure lib folders exist
file:
path: '{{item}}'
state: directory
recurse: true
loop:
- '{{LIB_DIR_NPM_BIN}}'
- '{{LIB_DIR_BIN}}'
when: BINPROVIDERS.npm is not defined
###################################################################################
- 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
when: BINPROVIDERS.npm is not defined
- 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}}"
when: BINPROVIDERS.npm is not defined
- set_fact:
BINPROVIDERS: "{{ BINPROVIDERS | default({}) | combine(NODE_BINPROVIDERS) }}"
cacheable: true
when: BINPROVIDERS.npm is not defined
- debug:
msg: "{{ {'BINARIES': BINARIES, 'BINPROVIDERS': BINPROVIDERS} }}"