consolidate ansible setup into roles dir

This commit is contained in:
Nick Sweeting 2024-09-17 00:48:47 -07:00
parent 25db6826ec
commit c55cd46ecb
No known key found for this signature in database
27 changed files with 763 additions and 91 deletions

View file

@ -0,0 +1,31 @@
---
argument_specs:
main:
short_description: Main entry point for the npm role
options:
state:
type: "str"
required: false
default: 'present'
description:
- "The desired state: present | latest"
npm_packages:
type: "list"
elements: "dict"
required: false
default: []
description: "A list of dicts with a defined structure and with default a value."
options:
key:
type: "str"
required: true
description: "A string name for the dependency"
packages:
type: "list"
elements: "str"
required: true
description: "What npm packages to install for the given dependency."

View file

@ -0,0 +1,59 @@
---
- name: Make sure lib folders exist
file:
path: '{{item}}'
state: directory
recurse: true
loop:
- '{{LIB_DIR_NPM_BIN}}'
- '{{LIB_DIR_BIN}}'
- name: "Install system packages: [node, npm]"
ansible.builtin.package:
name: "node"
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} }}"

View file

@ -0,0 +1,7 @@
DATA_DIR: '{{playbook_dir}}'
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'