Install as non-root user
ngstigator opened this issue · 2 comments
Installing in a vagrant environment. Playbook as follows:
- role: stephdewit.nvm
become: yes
become_user: vagrant
nvm_shell_init_file: ~/.bashrc
Error log:
TASK [nvm : Install Node.js 12.13.0] *****************************************************************
fatal: [192.168.33.22]: FAILED! => {"changed": true, "cmd": ". ~/.bashrc && nvm install 12.13.0", "delta": "0:00:00.001649", "end": "2019-12-30 18:32:02.526579", "msg": "non-zero return code", "rc": 127, "start": "2019-12-30 18:32:02.524930", "stderr": "/bin/sh: 1: nvm: not found", "stderr_lines": ["/bin/sh: 1: nvm: not found"], "stdout": "", "stdout_lines": []}
nvm
is installed for the vagrant user, but installing node fails. Installing node as vagrant user via the command line works as expected.
$ nvm install 12.13.0
Downloading and installing node v12.13.0...
Local cache found: ${NVM_DIR}/.cache/bin/node-v12.13.0-linux-x64/node-v12.13.0-linux-x64.tar.xz
Checksums match! Using existing downloaded archive ${NVM_DIR}/.cache/bin/node-v12.13.0-linux-x64/node-v12.13.0-linux-x64.tar.xz
Now using node v12.13.0 (npm v6.12.0)
Hello.
Sorry for the delay, I had a really busy month.
Except you really need it, you should remove the nvm_shell_init_file: ~/.bashrc
line from your playbook. I know it was in the example, and I removed it because it was misleading.
.bashrc
is meant for interactive shells and should probably not be used here.
Moreover I did some tests and found that when running with become
I had to set the NVM_DIR
variable to an absolute path to get everything working. I added an example in the README file.
Let me know if it helps!
Thanks for the commit! The become
instructions work as advertised. nvm
, node
, and npm
are all accessible after source ~/.bashrc
.