GithubHelp home page GithubHelp logo

morgangraphics / ansible-role-nvm Goto Github PK

View Code? Open in Web Editor NEW
94.0 5.0 29.0 143 KB

Installs NVM & Node.js on Debian/Ubuntu and RHEL/CentOS

License: MIT License

ansible-roles nvm-installation ansible nvm nvm-commands node-version-manager

ansible-role-nvm's People

Contributors

danhulton avatar morgangraphics avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

ansible-role-nvm's Issues

node: /lib/x86_64-linux-gnu/libc.so.6: version `GLIBC_2.28' not found (required by node)

Describe the bug
This is an issue with differing versions of Node and Ubuntu, not specifically an issue with NVM. However, this issue presents itself when running the role with the default --lts release on an OS that doesn't have the correct version of GLIBC e.g. Node 18.x and Ubuntu 18

Expected behavior
That the --lts version of Node work properly

To Reproduce

  roles:
      - role: ansible-role-nvm

Shell [e.g. bash, dash, ksh, tcsh, zsh]

Desktop (please complete the following information):

  • OS: Ubuntu 18
  • Ansible 7
  • Virtualbox 7

Install NVM step needs pipefail

Describe the bug
If the wget command fails for any reasons during the "Install NVM" the error is ignored, and then the check nvm version step fails later.

Expected behaviour
The "Install NVM" command should fail when the wget command fails instead of ignoring it

To Reproduce
Use bad proxy environment settings and wget will fail with return code 8.

Shell
Bash

Desktop (please complete the following information):

  • OS: RHEL 7.4
  • Ansible Version 2.9.10

Additional context
For bash this should be fixable by setting pipefail. Eg: https://blog.christophersmart.com/2019/09/28/using-pipefail-with-shell-module-in-ansible/

Set default: true is not idempotent

- hosts: foo
  roles:
    - role: ansible-role-nvm
      nodejs_version: "8.15.0"

    - role: ansible-role-nvm
      nodejs_version: "10.15.0"
      default: true

triggers a change when run multiple times and is not idempotent.

Check NVM Version fails if fallback shell is used

When nvm_profile is set to path that doesn't contain bash/zsh/csh/tcsh, role will fall back to setting user_shell.command to /etc/bash -ic and fail the first time it is used:

TASK [morgangraphics.ansible_role_nvm : Check NVM Version] *********************
fatal: [default]: FAILED! => {"changed": true, "cmd": "/etc/bash -ic \"nvm --version\"", "delta": "0:00:00.002488", "end": "2022-05-26 12:32:01.105866", "msg": "non-zero return code", "rc": 127, "start": "2022-05-26 12:32:01.103378", "stderr": "/bin/sh: 1: /etc/bash: not found", "stderr_lines": ["/bin/sh: 1: /etc/bash: not found"], "stdout": "", "stdout_lines": []}

I am pretty confident it should have been /bin/bash -ic.

I don't know if any distro ever shipped /etc/bash (most popular, like Ubuntu or Fedora, don't). And even if it did, it was probably some kind of configuration file, not executable.

file (.bashrc) is absent, cannot continue + nvm command not found

Describe the bug
Running this role without setting nvm_profile fails on task Update profile permissions to lock it down after writing although ~/.bashrc exists

Setting nvm_profile:

nvm_profile: "/home/{{ user_name }}/.bashrc"

this task passes but fails on task Check NVM Version with error:

bash: nvm: command not found

Tried the suggestion on #16 but still no success.

Expected behavior
NVM version be installed and verified with no errors.

To Reproduce
Minimally viable playbook to recreate the issue you are experiencing

  - role: morgangraphics.ansible_role_nvm
    nvm_user: "{{ user_name }}"
    nvm_version: "v0.35.2"
    nvm_profile: "/home/{{ user_name }}/.bashrc"
    nodejs_version: "12.16.1"
    # become: yes # tried with and without become and become_user, and the error was the same
    # become_user: "{{ user_name }}"

Desktop (please complete the following information):

  • OS: Ubuntu 18.04 docker container from OSX base OS, targeting another Ubuntu 18.04 docker container
  • Ansible Version: 2.9.9
  • Hypervisor Type and Version: Docker 19.03.8

Debugging output
The issue seen in the playbook output [e.g. ansible-playbook <YOUR_PLAYBOOK> --verbose -vvvv]

fatal: [172.19.0.1]: FAILED! => {
    "changed": true, 
    "cmd": "/bin/bash -ic \"nvm --version\"", 
    "delta": "0:00:00.042745", 
    "end": "2020-06-09 15:42:26.911514", 
    "invocation": {
        "module_args": {
            "_raw_params": "/bin/bash -ic \"nvm --version\"", 
            "_uses_shell": true, 
            "argv": null, 
            "chdir": null, 
            "creates": null, 
            "executable": null, 
            "removes": null, 
            "stdin": null, 
            "stdin_add_newline": true, 
            "strip_empty_ends": true, 
            "warn": true
        }
    }, 
    "rc": 127, 
    "start": "2020-06-09 15:42:26.868769"
}

STDERR:

bash: cannot set terminal process group (39047): Inappropriate ioctl for device
bash: no job control in this shell
bash: nvm: command not found


MSG:

non-zero return code

Additional context
Any suggestions on what I am doing wrong?

bash: nvm command not found

Describe the bug
hello, I'm not sure if this is a "bug", but I don't know where else to ask.
I'm trying to install a specific version of nvm, node, npm on a machine image using packer, however it keeps failing no matter what I try.

Expected behavior
that it installs and passes

To Reproduce

---

- hosts: all
  become: yes
  become_method: sudo

  roles:
    - role: ansible-role-nvm
      nodejs_version: "8.16.0"
      nvm_install: "curl"
      nvm_version: "0.34.0"
      nvm_profile: "/home/nodejs/.bashrc"
      nvm_dir: "/home/nodejs"
      nvm_commands:
       - "nvm install 8.16.0"
       - "nvm alias default 8.16.0"
       - "nvm exec default npm install"

Shell [e.g. Bash, Dash, ksh, tcsh, zsh]
bash
Desktop (please complete the following information):

  • OS: Debian stretch
  • Ansible Version: 2.2.1.0
  • Hypervisor Type and Version packer image on aws

Debugging output

    amazon-ebs:
    amazon-ebs: PLAY [all] *********************************************************************
    amazon-ebs:
    amazon-ebs: TASK [setup] *******************************************************************
    amazon-ebs: ok: [default]
    amazon-ebs:
    amazon-ebs: TASK [ansible-role-nvm : Check if wget or curl is installed] *******************
    amazon-ebs: changed: [default]
    amazon-ebs:
    amazon-ebs: TASK [ansible-role-nvm : Determine if install type wget] ***********************
    amazon-ebs: skipping: [default]
    amazon-ebs:
    amazon-ebs: TASK [ansible-role-nvm : Determine if install type curl] ***********************
    amazon-ebs: ok: [default]
    amazon-ebs:
    amazon-ebs: TASK [ansible-role-nvm : Create destination dir if it does not exist] **********
    amazon-ebs: changed: [default]
    amazon-ebs:
    amazon-ebs: TASK [ansible-role-nvm : Install NVM] ******************************************
    amazon-ebs: changed: [default]
    amazon-ebs:
    amazon-ebs: TASK [ansible-role-nvm : Check if git is installed] ****************************
    amazon-ebs: skipping: [default]
    amazon-ebs:
    amazon-ebs: TASK [ansible-role-nvm : Remove NVM nvm_profile] *******************************
    amazon-ebs: skipping: [default]
    amazon-ebs:
    amazon-ebs: TASK [ansible-role-nvm : Install via git] **************************************
    amazon-ebs: skipping: [default]
    amazon-ebs:
    amazon-ebs: TASK [ansible-role-nvm : Add NVM to nvm_profile] *******************************
    amazon-ebs: skipping: [default]
    amazon-ebs:
    amazon-ebs: TASK [ansible-role-nvm : Check NVM Version] ************************************
    amazon-ebs: fatal: [default]: FAILED! => {"changed": true, "cmd": "bash -ic \"nvm --version\"", "delta": "0:00:00.004018", "end": "2020-01-29 16:08:19.774321", "failed": true, "rc": 127, "start": "2020-01-29 16:08:19.770303", "stderr": "bash: cannot set terminal process group (12602): Inappropriate ioctl for device\nbash: no job control in this shell\nbash: nvm: command not found", "stdout": "", "stdout_lines": [], "warnings": []}
    amazon-ebs:         to retry, use: --limit @/home/admin/eu-sysops-packer/unified-API/unified-api-nodejs.retry
    amazon-ebs:
    amazon-ebs: PLAY RECAP *********************************************************************
    amazon-ebs: default                    : ok=5    changed=3    unreachable=0    failed=1
    amazon-ebs:

Additional context
this may be an issue with packer, the problem seems to occur whatever I do, I need to install all this under a specific user created earlier on in the AMI creation process

any advice gratefully received.

Many thanks

Custom nvm_dir does not work in protected directories like /opt/nvm out of the box

As described in #26 there is a bug where declaring a custom nvm directory location does not work properly out of the box. This is a permissions issues related to the user running the playbook and associations with group(s) or being added to the sudoers file. A temporary workaround is to assign the directory to the specific user until we address things properly with #26.

You have $NVM_DIR set to \"/home/user/.nvm\", but that directory does not exist.

Hello

When I run this role, using:

  - include_role: 
      name: ansible-role-nvm
    vars:
      nodejs_version: "4.8.0"

I get the following:

fatal: [127.0.0.1]: FAILED! => {"changed": true, "cmd": "wget -qO- https://raw.githubusercontent.com/creationix/nvm/v0.33.11/install.sh | NVM_SOURCE= NVM_DIR=/home/user/.nvm PROFILE=.bashrc bash", "delta": "0:00:00.297033", "end": "2019-02-21 09:56:42.735199", "msg": "non-zero return code", "rc": 1, "start": "2019-02-21 09:56:42.438166", "stderr": "You have $NVM_DIR set to \"/home/user/.nvm\", but that directory does not exist. Check your profile files and environment.", "stderr_lines": ["You have $NVM_DIR set to \"/home/user/.nvm\", but that directory does not exist. Check your profile files and environment."], "stdout": "", "stdout_lines": []}

Role fails on nvm commands if connection=local

Describe the bug
The role fails on the first nvm command it comes across if the role is run with a local connection rather than ssh. It doesn't have access to the nvm commands as they aren't being sourced.

Expected behavior
nvm.sh needs to be sourced in the tasks that utilize nvm so that the shell module can be run locally successfully. Normally this would be fine when connection method is ssh because they get sourced via .bashrc (although this role generates it's own in the playbooks directory in this scenario as well), but running locally doesn't seem to exhibit this behavior

To Reproduce
Ubuntu 22.04 host image
In a directory with the playbook, and relevant cloned /roles/ansible-role-nvm folder (or .ansible/roles etc)

- name: nvm test playbook
  hosts: 127.0.0.1
  connection: local
  roles:
    - role: ansible-role-nvm

Shell [e.g. Bash, Dash, ksh, tcsh, zsh]
bash

Desktop (please complete the following information):

  • OS: Ubuntu 22.04
  • Ansible Version : 2.12.0
  • Hypervisor Type and Version: WSL2 1.2.5.0

Debugging output

TASK [ansible-role-nvm : Check NVM Version] *********************************************************************************************************************************************************
task path: /home/pickles/ubuntu2204-wsl/roles/ansible-role-nvm/tasks/nvm.yml:157
<127.0.0.1> ESTABLISH LOCAL CONNECTION FOR USER: pickles
<127.0.0.1> EXEC /bin/sh -c 'echo ~pickles && sleep 0'
<127.0.0.1> EXEC /bin/sh -c '( umask 77 && mkdir -p "` echo /home/pickles/.ansible/tmp `"&& mkdir "` echo /home/pickles/.ansible/tmp/ansible-tmp-1690297067.3967338-22793-207818345201238 `" && echo ansible-tmp-1690297067.3967338-22793-207818345201238="` echo /home/pickles/.ansible/tmp/ansible-tmp-1690297067.3967338-22793-207818345201238 `" ) && sleep 0'                         Using module file /usr/lib/python3/dist-packages/ansible/modules/command.py
<127.0.0.1> PUT /home/pickles/.ansible/tmp/ansible-local-21568_10qrebw/tmpt0rp4hlp TO /home/pickles/.ansible/tmp/ansible-tmp-1690297067.3967338-22793-207818345201238/AnsiballZ_command.py
<127.0.0.1> EXEC /bin/sh -c 'chmod u+x /home/pickles/.ansible/tmp/ansible-tmp-1690297067.3967338-22793-207818345201238/ /home/pickles/.ansible/tmp/ansible-tmp-1690297067.3967338-22793-207818345201238/AnsiballZ_command.py && sleep 0'
<127.0.0.1> EXEC /bin/sh -c '/usr/bin/python3 /home/pickles/.ansible/tmp/ansible-tmp-1690297067.3967338-22793-207818345201238/AnsiballZ_command.py && sleep 0'
<127.0.0.1> EXEC /bin/sh -c 'rm -f -r /home/pickles/.ansible/tmp/ansible-tmp-1690297067.3967338-22793-207818345201238/ > /dev/null 2>&1 && sleep 0'
fatal: [localhost]: FAILED! => {
"changed": true,
"cmd": "/usr/bin/bash -ic \"nvm --version\"",
"delta": "0:00:00.107722",
"end": "2023-07-25 15:57:47.708570",
"invocation": {
     "module_args": {
            "_raw_params": "/usr/bin/bash -ic \"nvm --version\"",
            "_uses_shell": true, 
            "argv": null,
            "chdir": null,
            "creates": null,
            "executable": null,
            "removes": null,
            "stdin": null,
            "stdin_add_newline": true,
            "strip_empty_ends": true,
            "warn": false
        }
    },
    "msg": "non-zero return code",
    "rc": 127,
    "start": "2023-07-25 15:57:47.600848",
    "stderr": "Command 'nvm' not found, did you mean:\n  command 'gvm' from snap gvm (1.1.0)\n  command 'nsm' from snap nift (3.0.2)\n  command 'nvim' from snap nvim (v0.9.1)\n  command 'nam' from deb nam (1.15-5.2)\n  command 'npm' from deb npm (8.5.1~ds-1)\n  command 'nvme' from deb nvme-cli (1.16-3ubuntu0.1)\n  command 'nsm' from deb linuxptp (3.1.1-3)\n  command 'nvi' from deb nvi (1.81.6-17)\n  command 'nvim' from deb neovim (0.6.1-3)\n  command 'num' from deb quickcal (2.4-1)\n  command 'lvm' from deb lvm2 (2.03.11-2.1ubuntu4)\n  command 'nm' from deb binutils (2.38-4ubuntu2.2)\n  command 'kvm' from deb qemu-system-x86 (1:6.2+dfsg-2ubuntu6.12)\n  command 'vm' from deb mgetty-voice (1.2.1-1.1)\n  command 'pvm' from deb pvm (3.4.6-3.2)\nSee 'snap info <snapname>' for additional versions.",
    "stderr_lines": [
        "Command 'nvm' not found, did you mean:",
        "  command 'gvm' from snap gvm (1.1.0)",
        "  command 'nsm' from snap nift (3.0.2)",
        "  command 'nvim' from snap nvim (v0.9.1)",
        "  command 'nam' from deb nam (1.15-5.2)",
        "  command 'npm' from deb npm (8.5.1~ds-1)",
        "  command 'nvme' from deb nvme-cli (1.16-3ubuntu0.1)",
        "  command 'nsm' from deb linuxptp (3.1.1-3)",
        "  command 'nvi' from deb nvi (1.81.6-17)",
        "  command 'nvim' from deb neovim (0.6.1-3)",
        "  command 'num' from deb quickcal (2.4-1)",
        "  command 'lvm' from deb lvm2 (2.03.11-2.1ubuntu4)",
        "  command 'nm' from deb binutils (2.38-4ubuntu2.2)",
        "  command 'kvm' from deb qemu-system-x86 (1:6.2+dfsg-2ubuntu6.12)",
        "  command 'vm' from deb mgetty-voice (1.2.1-1.1)",
        "  command 'pvm' from deb pvm (3.4.6-3.2)",
        "See 'snap info <snapname>' for additional versions."
    ],
    "stdout": "",
    "stdout_lines": []
}

Additional context
I question if this is the same as #15 but since they didn't give enough information, it is hard to tell. You can test whether or not the local (sub)shell will have access to nvm by entering bash in a terminal and trying any nvm command.

autocomplete functionality is now installed by default

Have to switch the documentation and default value associated with autocomplete. nvm-sh installs/sets it up by default.

autocomplete: true will preserve the default auto-completion
autocomplete: false will remove the feature

NVM Global install Option

Installing NVM in a global space e.g. /opt/nvm requires that:

  1. The destination directory and grand/parent directories are not protected or limited by permissions of which the become_user are not a part of
  2. The become_user has sudoers access to be able to create directories in the file system and execute commands in that space
  3. The become_user is part of a group that has some sudoers access to create directories in the file system and execute commands in that space

While the role will work if these scenarios have been addressed before hand (the user handles it themselves outside this role), it might be beneficial to have a global_install option that will set up the appropriate secure/least privilege permissions to handle permission sensitive install scenarios. e.g. nvm-users

As it stands now, installing in /opt/nvm requires that you have root permissions to create the directory and to run the install.sh file which in turn tries to create a series of other directories under /opt/nvm like /opt/nvm/[.cache|alias]. Consequently, by adding become: true and become_user: root the nvm script execution will attempt to install Node as root, you can't install Node as root and will subsequently fail.

Install NVM task fails on Ansible 7/core 2.14

Hi @morgangraphics - thanks for this useful role!

Describe the bug
When I try to run this role with Ansible 7/core 2.14.1 installed, it fails at the "Install NVM task" with the following error:

fatal: [myhostname.local]: FAILED! => {"changed": false, "changed_when_result": "The conditional check ''already installed' not in nvm_result.stdout' failed. The error was: error while evaluating conditional ('already installed' not in nvm_result.stdout): 'dict object' has no attribute 'stdout'. 'dict object' has no attribute 'stdout'", "msg": "Unsupported parameters for (ansible.legacy.command) module: warn. Supported parameters include: executable, stdin_add_newline, _uses_shell, creates, _raw_params, strip_empty_ends, removes, stdin, chdir, argv."}

I believe this is because the warn parameter was deprecated and removed in the latest Ansible version. If I comment out these lines in tasks.yml, the task runs correctly:

#    args:
#      warn: false

I'd be happy to submit a PR removing these lines if, however I'm not enough of an Ansible expert to determine if that needs to be replaced with something, or if there are any other changes required to support Ansible core 2.14.

Expected behavior
The role should install NVM without throwing an error in the latest version of Ansible

To Reproduce

  • Install the latest version of ansible
  • Clone this repo into roles
  • Make a playbook:
- name: test the thing
  hosts: homelab
  roles:
    - role: ansible-role-nvm
      nodejs_version: "lts/gallium" # Node 16

Shell [e.g. Bash, Dash, ksh, tcsh, zsh]
zsh on control node, bash on managed node

Desktop (please complete the following information):

  • OS: OSX
  • Ansible Version: Ansible Community 7 / core 2.14.1

Check NVM Version: "bash: nvm: command not found"

Hi,
I'm trying this role for the first time on an AWS EC2 instance, Amazon Linux AMI 2018.03.0.20180811 x86_64 HVM GP2 and running into this error while executing the playbook through a Jenkins job, using the latest build of Jenkins (ver. 2.150). Any suggestions would be appreciated, thanks!

PLAY [all] *********************************************************************

TASK [Gathering Facts] *********************************************************
ok: [ec2-foo-bar.compute-1.amazonaws.com]

TASK [include_role] ************************************************************

TASK [../roles/ansible-role-nvm : Check if wget or curl is installed] **********
changed: [ec2-foo-bar.compute-1.amazonaws.com]

TASK [../roles/ansible-role-nvm : Determine if install type wget] **************
ok: [ec2-foo-bar.compute-1.amazonaws.com]

TASK [../roles/ansible-role-nvm : Determine if install type curl] **************
skipping: [ec2-foo-bar.compute-1.amazonaws.com]

TASK [../roles/ansible-role-nvm : Install NVM] *********************************
 [WARNING]: Consider using the get_url or uri module rather than running wget.
If you need to use command because get_url or uri is insufficient you can add
warn=False to this command task or set command_warnings=False in ansible.cfg to
get rid of this message.
changed: [ec2-foo-bar.compute-1.amazonaws.com]

TASK [../roles/ansible-role-nvm : Check if git is installed] *******************
skipping: [ec2-foo-bar.compute-1.amazonaws.com]

TASK [../roles/ansible-role-nvm : Remove NVM to nvm_profile] *******************
skipping: [ec2-foo-bar.compute-1.amazonaws.com]

TASK [../roles/ansible-role-nvm : Install via git] *****************************
skipping: [ec2-foo-bar.compute-1.amazonaws.com]

TASK [../roles/ansible-role-nvm : Add NVM to nvm_profile] **********************
skipping: [ec2-foo-bar.compute-1.amazonaws.com]

TASK [../roles/ansible-role-nvm : Check NVM Version] ***************************
fatal: [ec2-foo-bar.compute-1.amazonaws.com]: FAILED! => {"changed": true, "cmd": "bash -ic \"nvm --version\"", "delta": "0:00:00.012111", "end": "2018-11-05 22:45:00.754177", "msg": "non-zero return code", "rc": 127, "start": "2018-11-05 22:45:00.742066", "stderr": "bash: no job control in this shell\nbash: nvm: command not found", "stderr_lines": ["bash: no job control in this shell", "bash: nvm: command not found"], "stdout": "", "stdout_lines": []}

PLAY RECAP *********************************************************************
ec2-foo-bar.compute-1.amazonaws.com : ok=7    changed=2    unreachable=0    failed=1   

FATAL: command execution failed
hudson.AbortException: Ansible playbook execution failed
	at org.jenkinsci.plugins.ansible.AnsiblePlaybookBuilder.perform(AnsiblePlaybookBuilder.java:262)
	at org.jenkinsci.plugins.ansible.AnsiblePlaybookBuilder.perform(AnsiblePlaybookBuilder.java:232)
	at hudson.tasks.BuildStepCompatibilityLayer.perform(BuildStepCompatibilityLayer.java:81)
	at hudson.tasks.BuildStepMonitor$1.perform(BuildStepMonitor.java:20)
	at hudson.model.AbstractBuild$AbstractBuildExecution.perform(AbstractBuild.java:744)
	at hudson.model.Build$BuildExecution.build(Build.java:206)
	at hudson.model.Build$BuildExecution.doRun(Build.java:163)
	at hudson.model.AbstractBuild$AbstractBuildExecution.run(AbstractBuild.java:504)
	at hudson.model.Run.execute(Run.java:1810)
	at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:43)
	at hudson.model.ResourceController.execute(ResourceController.java:97)
	at hudson.model.Executor.run(Executor.java:429)
$ ssh-agent -k
unset SSH_AUTH_SOCK;
unset SSH_AGENT_PID;
echo Agent pid 31494 killed;
[ssh-agent] Stopped.
ERROR: Ansible playbook execution failed
Finished: FAILURE

`/etc/bash` being used to check `nvm --version`

Describe the bug

TASK [ansible-role-nvm : Check NVM Version] ************************************
fatal: [default]: FAILED! => {"changed": true, "cmd": "/etc/bash -ic \"nvm --version\"", "delta": "0:00:00.002670", "end": "2020-05-23 19:35:04.916208", "msg": "non-zero return code", "rc": 127, "start": "2020-05-23 19:35:04.913538", "stderr": "/bin/sh: 1: /etc/bash: not found", "stderr_lines": ["/bin/sh: 1: /etc/bash: not found"], "stdout": "", "stdout_lines": []}

Expected behavior

TASK [ansible-role-nvm : Check NVM Version] ************************************
ok: [default]

To Reproduce
Attempt to run the role against a fresh Ubuntu 18.04 instance. I have tried with and without setting nvm_profile: ".bashrc" and get the same error.

Shell [e.g. Bash, Dash, ksh, tcsh, zsh]
Bash

Desktop (please complete the following information):

  • Host OS: 10.15.4 (19E287)
  • Guest OS: Ubuntu 18.04
  • Ansible Version: 2.9.6
  • Hypervisor Type and Version: VirtualBox: 6.1.6r137129

Debugging output

fatal: [default]: FAILED! => {
    "changed": true,
    "cmd": "/etc/bash -ic \"nvm --version\"",
    "delta": "0:00:00.002679",
    "end": "2020-05-23 19:47:43.688427",
    "invocation": {
        "module_args": {
            "_raw_params": "/etc/bash -ic \"nvm --version\"",
            "_uses_shell": true,
            "argv": null,
            "chdir": null,
            "creates": null,
            "executable": null,
            "removes": null,
            "stdin": null,
            "stdin_add_newline": true,
            "strip_empty_ends": true,
            "warn": true
        }
    },
    "msg": "non-zero return code",
    "rc": 127,
    "start": "2020-05-23 19:47:43.685748",
    "stderr": "/bin/sh: 1: /etc/bash: not found",
    "stderr_lines": [
        "/bin/sh: 1: /etc/bash: not found"
    ],
    "stdout": "",
    "stdout_lines": []
}

Additional context
I did some digging around, trying to see why it was using /etc/bash, and it appears the role is running the following task:

    - name: "!WARNING! set unrecommended default for any other nvm_profile value !WARNING!"
      set_fact:
        user_shell: { 'command': '/etc/bash -ic', 'alias': 'bash' }
      when: (shell_path is undefined) or (found_path | bool == False)

Breaking that conditional down a little further, I found that:

"(shell_path is undefined)": false

But

"found_path | bool": false

Which is weird, because:

"found_path": "/bin/bash"

I'm not sure why casting /bin/bash to bool is False, but it looks like that's what's causing that conditional to be true, and what's causing the weird bash location that's tripping up my install. Thoughts?

Ubuntu 18.04 - Check NVM Version: "bash: nvm: command not found"

Following up from

#1

Hello I am encountering this problem on an Ubuntu 18.04 machine. Setting or unsetting the nodejs_version does not seem to have an effect.

Ansible Version:
fotis➜ ansible : development ✘ :✖✹✭ ᐅ ansible --version ansible 2.8.3 executable location = /usr/local/bin/ansible python version = 3.7.4 (default, Jul 9 2019, 18:13:23) [Clang 10.0.1 (clang-1001.0.46.4)]

This is the output.
TASK [ansible-role-nvm : Check NVM Version] ************************************ fatal: [default]: FAILED! => {"changed": true, "cmd": "bash -ic "nvm --version"", "delta": "0:00:00.088530", "end": "2020-01-11 13:08:13.807246", "msg": "non-zero return code", "rc": 127, "start": "2020-01-11 13:08:13.718716", "stderr": "\nCommand 'nvm' not found, did you mean:\n\n command 'gvm' from snap gvm (1.1.0)\n command 'nsm' from snap nift (2.0.1)\n command 'npm' from deb npm\n command 'nvme' from deb nvme-cli\n command 'nm' from deb binutils\n command 'nim' from deb nim\n command 'nam' from deb nam\n command 'kvm' from deb qemu-kvm\n command 'nvim' from deb neovim\n command 'lvm' from deb lvm2\n command 'num' from deb quickcal\n command 'pvm' from deb pvm\n command 'vm' from deb mgetty-voice\n command 'nvi' from deb nvi\n\nSee 'snap info ' for additional versions.", "stderr_lines": ["", "Command 'nvm' not found, did you mean:", "", " command 'gvm' from snap gvm (1.1.0)", " command 'nsm' from snap nift (2.0.1)", " command 'npm' from deb npm", " command 'nvme' from deb nvme-cli", " command 'nm' from deb binutils", " command 'nim' from deb nim", " command 'nam' from deb nam", " command 'kvm' from deb qemu-kvm", " command 'nvim' from deb neovim", " command 'lvm' from deb lvm2", " command 'num' from deb quickcal", " command 'pvm' from deb pvm", " command 'vm' from deb mgetty-voice", " command 'nvi' from deb nvi", "", "See 'snap info ' for additional versions."], "stdout": "", "stdout_lines": []}

Galaxy version outdated?

Hi,
Thanks for providing this NVM role to the community! It's pretty useful.

I just installed the version from Ansible Galaxy and noticed that the version there says Last commit 6 months ago whereas in this github repository there have been commits in the past 2 months:
https://galaxy.ansible.com/morgangraphics/ansible_role_nvm

Perhaps might be a good idea to auto import on git push to master using TravisCI:
https://galaxy.ansible.com/docs/contributing/importing.html#import-roles-via-travis-ci

Check version fails on OSX

Describe the bug
On OSX, an error occurs trying to check the nvm version.

Expected behavior
nvm version check passes normally

To Reproduce

- role: nvm
  nvm_profile: '.zshrc'

Shell [e.g. Bash, Dash, ksh, tcsh, zsh]

ZSH

Desktop (please complete the following information):

  • OS: [e.g. Ubuntu 18.04, CentOS, OSX]: OSX
  • Ansible Version: 2.9.6
  • Hypervisor Type and Version [e.g. Virtualbox 6, VMWARE ESX, Docker 19.03, etc]: N/A?

Debugging output

TASK [nvm : Check NVM Version] ***********************************************************************
fatal: [localhost]: FAILED! => {"changed": true, "cmd": "bash -ic \"nvm --version\"", "delta": "0:00:00.012799", "end": "2020-03-28 17:30:18.724566", "msg": "non-zero return code", "rc": 127, "start": "2020-03-28 17:30:18.711767", "stderr": "bash: no job control in this shell\nbash: nvm: command not found", "stderr_lines": ["bash: no job control in this shell", "bash: nvm: command not found"], "stdout": "", "stdout_lines": []}

Additional context
N/A

Add default: True role variable to ensure NVM default alias is set correctly

As described in this PR comment

#7 (comment)

To sum it up, perhaps what you are suggesting is that there should be a new role variable that is something like: default: True so whichever version you explicitly state, is aliased as the default NodeJS version to run. All this would do is append/concatenate the nvm alias default {{ nodejs_version }} command to the {{ nvm_commands }} list making the version explicitly declared as the default, mitigating the need for a separate one off "nvm use {{ nodejs_version }} task. (It'd just make it more generic using already existing stuff) e.g.

- hosts: host1
  roles:
    - role: ansible-role-nvm
      nodejs_version: "10.15.1"
      default: True

- hosts: host1
  roles:
    - role: ansible-role-nvm
      nodejs_version: "8.15.0"

The added benefit is that if there are other versions on the machine that you want to leverage, you could then take advantage of the nvm_commands: [] role variable itself. This brings me to the other point of having to update the documentation to explain the nvm_commands: [] variable in further detail.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.