Closed Clumsy-Coder closed 1 year ago
Figured out a solution
roles/npm/tasks/main.yaml
- name: "Store current nodejs version being used by nvm"
shell: "source {{ ansible_env.NVM_DIR}}/nvm.sh && nvm current"
register: node_version
changed_when: false
- name: "Install global npm packages"
npm:
name: "{{ item }}"
global: true
# executable: "{{ ansible_env.NVM_DIR}}/versions/node/{{ node_version.stdout }}/bin/npm"
loop:
- commitizen
- typescript
environment:
# obtained from https://truongtx.me/2015/11/02/ansible-install-and-work-with-nodejs-using-nvm#install-npm-tools-with-node-in-nvm
PATH: "{{ ansible_env.NVM_DIR }}/versions/node/{{ node_version.stdout }}/bin:{{ ansible_env.PATH }}"
You should never need to hardcode paths to node; the issue is that whatever sources nvm and use
s a version needs to export the PATH for future steps to use.
Operating system and version:
MacOS Catalina (10.15.7)
nvm debug
output:nvm ls
output:Ansible is unable to find
node
when installing npm packages.roles/nvm/tasks/main.yaml
roles/npm/tasks/main.yaml
playbooks/macos.yaml
ansible.cfg
roles.yaml
command to run
ANSIBLE_CONFIG=./ansible.cfg ansible-playbook "./playbooks/macos.yaml" --ask-become-pass --verbose
output