Installation of Node Version Manager ( NVM ) when Provisioning Vagrant

1,115 views
Skip to first unread message

Ifiok Jr.

unread,
Sep 12, 2013, 11:20:51 AM9/12/13
to salt-...@googlegroups.com
I'm trying to provision a vagrant development server to start up with Node Version Manager. This is so I can quickly change between versions of node while in development.

The code I'm using - while it does work when entered manually - doesn't work with the Salt Config that I'm using. The manual installation instructions that I'm following are outlined here: https://github.com/creationix/nvm

Here is the code in my nvm/init.sls:

nvm:
  cmd:
    - cwd: /tmp
    - names:
        - . ~/.nvm/nvm.sh
    - run
    - require:
      - pkg: git

# Use NVM to obtain latest node versions and choose one to use.

node:
  cmd:
    - names:
      - nvm install 0.80
      - nvm install 0.11
      - nvm install 0.10
      - nvm use 0.10
    - run
    - require:
      - cmd: nvm

And here are the relevant return messages:

State: - cmd
    Function:  run
        Result:    True
        Comment:   Command "wget -qO- https://raw.github.com/creationix/nvm/master/install.sh | sh" run
        Changes:   pid: 4959
                   retcode: 0
                   stderr:
                   stdout: => NVM is already installed in /root/.nvm, trying to update
=>
Already up-to-date.

=> Source string already in /root/.profile
=> Close and reopen your terminal to start using NVM

----------
    State: - cmd
    Name:      nvm install 0.10
    Function:  run
        Result:    False
        Comment:   Command "nvm install 0.10" run
        Changes:   pid: 4990
                   retcode: 127
                   stderr: /bin/bash: nvm: command not found
                   stdout:

----------
    State: - cmd
    Name:      nvm install 0.11
    Function:  run
        Result:    False
        Comment:   Command "nvm install 0.11" run
        Changes:   pid: 4991
                   retcode: 127
                   stderr: /bin/bash: nvm: command not found
                   stdout:

----------
    State: - cmd
    Name:      nvm install 0.80
    Function:  run
        Result:    False
        Comment:   Command "nvm install 0.80" run
        Changes:   pid: 4992
                   retcode: 127
                   stderr: /bin/bash: nvm: command not found
                   stdout:

----------
    State: - cmd
    Name:      nvm use 0.10
    Function:  run
        Result:    False
        Comment:   Command "nvm use 0.10" run
        Changes:   pid: 4993
                   retcode: 127
                   stderr: /bin/bash: nvm: command not found
                   stdout:

----------

I think it's to do with the fact that the installation is performed by root and perhaps there's something that happens when trying to source ~/.nvm/nvm.sh with this code. 

Does anyone have any ideas which direction I could go?

I'd love to have an installation of nvm available for all users (which I can specify via pillars) as well as root. For now I'd be happy with a basic installation running for the vagrant user.

FYI: I'm using a vagrant configuration and layout almost identical to https://raw.github.com/raadad/node-dev-vagrant-example/master/Vagrantfile

Thanks

Colton Myers

unread,
Sep 12, 2013, 2:22:55 PM9/12/13
to salt-...@googlegroups.com
Where does the nvm binary reside?  Have you tried just giving an absolute path to the binary in your nvm install commands?

--
Colton Myers


--
You received this message because you are subscribed to the Google Groups "Salt-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to salt-users+...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Ifiok Jr.

unread,
Sep 12, 2013, 6:10:04 PM9/12/13
to salt-...@googlegroups.com
I'm actually reading through the bash install script now.

There's a couple of places that could have caused the problem to come up. Will test these out and then update you on outcomes. 


--
You received this message because you are subscribed to a topic in the Google Groups "Salt-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/salt-users/lAxgX4KZQOg/unsubscribe.
To unsubscribe from this group and all its topics, send an email to salt-users+...@googlegroups.com.

Ifiok Jr.

unread,
Sep 13, 2013, 7:12:00 AM9/13/13
to salt-...@googlegroups.com
It was a pretty good read. I can definitely say I have a better understanding of bash scripting now which is sure to be useful some time. 

Anyway, I've managed to solve my problem. It wasn't to do with the binary, as it wasn't even recognising nvm as a script. But there were a number of small problems. 

One problem was using ~/ without specifying a user or group to run it under. It's a pretty basic error. 

Also there were some issues with the shell being used not supporting the shell command source. I've found that when a user is created it defaults to /bin/sh shell which is the almost the worst looking shell known to man. So I've set - shell: /bin/bash in my user config and things are now working. Some of the relevant code is shown below.  

It's raised a few question on the structure of salt masters and salt minions that I'll post in another thread. I definitely need to understand many things better. 

{% for usr, val in pillar.get('users', {}).items() %}
{{ usr }}-nvm:
  file.recurse:
    - name: /home/{{ usr }}/.nvm
    - source: salt://repos/nvm
    - include_empty: True
    - user: {{ usr }}
    - group: {{ usr }}
  cmd.run:
    - name: source /home/{{ usr }}/.nvm/nvm.sh
    - cwd: /home/{{ usr }}/
    - user: {{ usr }}
    - group: {{ usr }}
    - require:
      - file: {{ usr }}-nvm

{{ usr }}-node:
  cmd.run:
    - names:
      - nvm install 0.80
      - nvm install 0.11
      - nvm install 0.10
      - nvm use 0.10
    - require:
      - cmd: {{ usr }}-nvm
    - user: {{ usr }}
    - group: {{ usr }}
{% endfor %}

PS:
I also cloned the git rep into my salt file root (under repos/nvm ). I felt that it's not efficient to hit github with increasing number of wget downloads (num_users * num_minions) when I can just pull it from the master.

I looked at gitfs_remotes and gitfs_root - but none would have made it any easier to namespace the repos. 


--
Colton Myers


To unsubscribe from this group and stop receiving emails from it, send an email to salt-users+unsubscribe@googlegroups.com.

For more options, visit https://groups.google.com/groups/opt_out.

--
You received this message because you are subscribed to a topic in the Google Groups "Salt-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/salt-users/lAxgX4KZQOg/unsubscribe.
To unsubscribe from this group and all its topics, send an email to salt-users+unsubscribe@googlegroups.com.

Colton Myers

unread,
Sep 13, 2013, 12:20:50 PM9/13/13
to salt-...@googlegroups.com
Glad you figured it out!

--
Colton Myers


To unsubscribe from this group and stop receiving emails from it, send an email to salt-users+...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages