pcriv / ansible-role-nvm

Role to install nvm and multiple nodejs versions.
MIT License
20 stars 19 forks source link

Fails during "install packages for each user" task #12

Open gregorskii opened 7 years ago

gregorskii commented 7 years ago

Hi there,

Finding this role fails while installing npm packages from the nvm_global_packages list.

The error appears to be due to the nvm_node_versions being "N/A", although the item being passed to the task includes the right value:

==> googlecompute: starting sftp subsystem
    googlecompute: failed: [default] (item=[u'jenkins', u'v6.6.0', u'gulp-cli']) => {"changed": true, "cmd": "bash -lc \"nvm use v6.6.0 && npm install -g gulp-cli\"", "delta": "0:00:00.069153", "end": "2016-10-10 03:21:01.181354", "failed": true, "item": ["jenkins", "v6.6.0", "gulp-cli"], "rc": 1, "start": "2016-10-10 03:21:01.112201", "stderr": "N/A: version \"N/A\" is not yet installed.\n\nYou need to run \"nvm install N/A\" to install it before using it.", "stdout": "", "stdout_lines": [], "warnings": []}

My config:


---

nvm_env: user
nvm_version: v0.32.0
nvm_default_node_version: "v{{nvm_node_version}}"
nvm_node_versions:
  - "v{{nvm_node_version}}"

nvm_global_packages: [
  'gulp-cli'
]

nvm_users: [
  'jenkins'
]

Thanks

pcriv commented 7 years ago

Hey @gregorskii, where are you setting the nvm_node_version

gregorskii commented 7 years ago

Hey @pablocrivella,

Its being passed into Ansible as a extra-var from shell:

local NODE_VERSION=$(cat ./.nvmrc | sed 's/v//g')
packer build IMAGE -var 'NODE_VERSION=${NODE_VERSION}'

Then to my main playbook from Packer:

{
  "type": "ansible",
  "playbook_file": "ansible/jenkins.yml",
  "extra_arguments": [
     "--extra-vars", "NODE_VERSION={{user `NODE_VERSION`}}"
  ]
},

Then to the playbook (ansible/jenkins.yml):

---

- hosts: all

  gather_facts: yes
  become: True

  vars:
    nvm_node_version: "{{NODE_VERSION}}"

  vars_files:
    - group_vars/nvm-vars.yml

  roles:
    - pablocrivella.nvm

Its evaluating to the string 6.6.0 when its in Ansible. I add the 'v' in Ansible "v{{nvm_node_version}}" as I was debugging whether the v mattered.

Ansible reports it installs the node version when in the nvm_env mode for user, but when it tries to install packages with that version nvm fails. It does however appear to work in system mode, but then I do not get user specific nvm versions and installations.

Thanks!

pcriv commented 7 years ago

Hey @gregorskii i will try to take a look at this later today