Salt State for NVM install Not Working

139 views
Skip to first unread message

Jay Ambi

unread,
Jul 26, 2016, 1:57:39 AM7/26/16
to Salt-users
Hiyas,

Currently just building a dev box running salt masterless. Everythings working except installing nvm & node.

I've tried next to everything and it's killing my will to live.

----------

curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.31.3/install.sh | bash:
  cmd.run

. ~/.nvm/nvm.sh; nvm install --lts:
  cmd.run

-----------

I'll keep it simple. It should just be 3 steps, the install via curl, then sourcing nvm and then installing node js.

However, the state keeps failing in 1 of 2 ways depending on my approach.

If I source nvm as it's own cmd.run, no matter what I do to source it (sourcing .bashrc or adding to /etc/profile), when it gets to the 'nvm install' part salt-call returns /bin/bash: nvm: command not found -- even though the nvm command will begin working for the root user outside of salt..

The other problem is the above state, if I source nvm and then try to 'nvm install --lts' on the same cmd.run, salt-call output returns that it succeeded, shows it installing node but then its nowhere to be found. Running nvm or 'node -v' as root or via salt-call returns nothing exists.

Not quite sure where its going wrong between the shell i'm in as root and the shell used by salt locally.

Does anyone have a working state for installing latest nvm & node?

Colton Myers

unread,
Jul 26, 2016, 1:15:37 PM7/26/16
to salt-...@googlegroups.com
You might consider adding a `python_shell: True` as an argument to your cmd.run states, since you're using pipes. Salt disables shell-isms by default in order to reduce the risk of command injection vulnerabilities.

--  
Colton Myers
@basepi
--
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/d/optout.

Paul Nickerson

unread,
Oct 2, 2018, 1:28:25 PM10/2/18
to Salt-users
For any future people who come across this post: Jay above says that it "shows it installing node but then its nowhere to be found". Looks like install.sh uses the $METHOD Bash environment variable to decide what installation method to use. If the variable is unset, then it auto chooses. If it's "git" or "script", then it uses those methods. If $METHOD is set to something else, then it skips installing and continues on with the script. Seems that Salt sets $METHOD to "loopback".

Adding this to cmd.run worked for me:
    - env:
      - METHOD: ''

I'm going to see if I can do a pull request on the NVM install.sh script and at least get it displaying an error message when $METHOD contains an unexpected string.

And relatedly, I figured out how to get Salt to use NVM to install a certain version of Node.js. Use this as your cmd.run. Note the period right at the start.
. /home/{{ user }}/.nvm/nvm.sh && nvm install {{ version }}

CONFIDENTIALITY NOTICE

The attached information is PRIVILEGED AND CONFIDENTIAL and is intended only for the use of the addressee named above.  If the reader of this message is not the intended recipient or the employee or agent responsible for delivering the message to the intended recipient, please be aware that any dissemination, distribution or duplication of this communication is strictly prohibited. If you receive this communication in error, please notify us immediately by telephone, delete the message and destroy any printed copy of the message. Thank you.

Reply all
Reply to author
Forward
0 new messages