grzegorznowak / ansible-nvm-node

Ansible role: global nvm node
https://galaxy.ansible.com/grzegorznowak/nvm_node
12 stars 13 forks source link

Support for global package version numbers #6

Closed mishawakerman closed 4 years ago

mishawakerman commented 4 years ago

Because of the symlinking step, setting nvm_install_globally: ["yarn@1.94"] will fail.

We worked around this by copying the global install and symlinking steps into our playbook manually and allowing for a a version to be included in the install step and ignored in the symlink step.

grzegorznowak commented 4 years ago

hey @mishawakerman , thanks for reporting that.

Can you please share parts of the afrementioned playbook and steps relevant for the discussion ?

Or even better just throw a PR if you feel like it.

I honestly didn't think about global packages' version targeting, so that's perfectly valid point up there.

mishawakerman commented 4 years ago

We ended up going in a different direction with how we installed global packages (we had only slightly-unrelated PATH issues further down in our playbook) but what we originally did was:

nvm_global_packages:
  - name: yarn
    version: 1.9.4
  - name: pm2
    version: 3.1.2

...

- name: Install global packages
  shell:
    cmd: ". /root/.bashrc && {{ nvm_dir }}/versions/node/v{{ nvm_node_version }}/bin/npm install --global {{ item.name }}@{{ item.version }}"
    creates: "{{ nvm_dir }}/versions/node/v{{ nvm_node_version }}/bin/{{ item.name }}"
  loop: "{{ nvm_global_packages }}"

- name: Symlink global packages into PATH for specific environments (like cron's) to be able to access them.
  file: src="{{ nvm_dir }}/versions/node/v{{ nvm_node_version }}/bin/{{ item.name }}"
        dest="/usr/bin/{{ item }}" state=link mode="u+rwx,g+rx,o+rx"
  loop: "{{ nvm_global_packages }}"
grzegorznowak commented 4 years ago

Right yes thanks @mishawakerman , I see how that could be incorporated into the role, with some Ansible if-ing.

grzegorznowak commented 4 years ago

Alright,

that feature should now be in place @mishawakerman . Version https://github.com/grzegorznowak/ansible-nvm-node/releases/tag/1.2.1

Usage outlined in README, hopefully will be clear to adjust.

It's 100% backwards compatible, so no need to update existing and working inventories/playbooks.

Please give it a try and let me know if it worked for you