Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

/etc/bash being used to check nvm --version #21

Closed
DanHulton opened this issue May 23, 2020 · 10 comments
Closed

/etc/bash being used to check nvm --version #21

DanHulton opened this issue May 23, 2020 · 10 comments
Assignees
Labels

Comments

@DanHulton
Copy link
Contributor

DanHulton commented May 23, 2020

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?

@morgangraphics
Copy link
Owner

I've just run it myself on a clean 18.04 instance with the .bashrc as a default without any issues.

F.Y.I Documentation has recently been added/updated to describe why running role as Root is bad and makes suggestions for what to do if running the role with different user profiles e.g. become_user: <user>

Are you doing anything special with users, user homes, user permissions?
Does the user actually exist on the system as a real user (you either used the Ansible user module or wrote something like sudo useradd -m <user>
Are you running this role (or all roles in a playbook) as root?
Could you provide a minimum viable playbook to reproduce the issue you are seeing?

@DanHulton
Copy link
Contributor Author

Huh, yeah, I read through the stuff about running as root, and I'm not. Lemme pare down what I have and put it up here.

@DanHulton
Copy link
Contributor Author

/Vagrantfile:

# -*- mode: ruby -*-
# vi: set ft=ruby :

Vagrant.configure("2") do |config|
  config.vm.box = "ubuntu/bionic64"
  config.vm.hostname = "example"

  config.ssh.insert_key = true
  config.ssh.forward_agent = true

  config.vm.network "private_network", ip: "192.168.33.13"

  config.vm.provider :virtualbox do |vb|
    vb.customize ["modifyvm", :id, "--memory", "1024"]
  end

  config.vm.provision "ansible" do |ansible|
#      ansible.verbose = 'vvvv'
      ansible.playbook = "ansible/develop.yml"
  end
end

/ansible/develop.yml:

---
- name: Set up app
  hosts: all

  vars:
    ansible_python_interpreter: python3

  roles:
    - ansible-role-nvm

Output (skipping Vagrant lines):

PLAY [Set up app] **************************************************************

TASK [Gathering Facts] *********************************************************
ok: [default]

TASK [ansible-role-nvm : set default found path] *******************************
ok: [default]

TASK [ansible-role-nvm : test for shells] **************************************
changed: [default] => (item=bash)
skipping: [default] => (item=dash)
skipping: [default] => (item=zsh)
skipping: [default] => (item=csh)
skipping: [default] => (item=tcsh)

TASK [ansible-role-nvm : set found path] ***************************************
ok: [default]

TASK [ansible-role-nvm : set bash command] *************************************
ok: [default]

TASK [ansible-role-nvm : set zsh command] **************************************
skipping: [default]

TASK [ansible-role-nvm : set csh command] **************************************
skipping: [default]

TASK [ansible-role-nvm : set tcsh command] *************************************
skipping: [default]

TASK [ansible-role-nvm : !WARNING! set unrecommended default for any other nvm_profile value !WARNING!] ***
ok: [default]

TASK [ansible-role-nvm : does profile file exist] ******************************
ok: [default]

TASK [ansible-role-nvm : Create profile file if it does not exist] *************
skipping: [default]

TASK [ansible-role-nvm : Check if wget or curl is installed] *******************
ok: [default]

TASK [ansible-role-nvm : Determine if install type wget] ***********************
ok: [default]

TASK [ansible-role-nvm : Determine if install type curl] ***********************
skipping: [default]

TASK [ansible-role-nvm : Create nvm_dir if it does not exist] ******************
skipping: [default]

TASK [ansible-role-nvm : Install NVM] ******************************************
changed: [default]

TASK [ansible-role-nvm : Update profile permissions to lock it down after writing] ***
skipping: [default]

TASK [ansible-role-nvm : Check if git is installed] ****************************
skipping: [default]

TASK [ansible-role-nvm : Remove NVM nvm_profile] *******************************
skipping: [default]

TASK [ansible-role-nvm : Install via git] **************************************
skipping: [default]

TASK [ansible-role-nvm : Add NVM to nvm_profile] *******************************
skipping: [default]

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

PLAY RECAP *********************************************************************
default                    : ok=10   changed=2    unreachable=0    failed=1    skipped=11   rescued=0    ignored=0

@DanHulton
Copy link
Contributor Author

And one small thing that might looks weird - I used to install this role directly from github because the Ansible Galaxy version was behind, hence why the role is referenced as ansible-role-nvm. I tried using the Ansible Galaxy install instructions directly and referencing the role as morgangraphics.ansible_role_nvm, but it still sets the unrecommended default and blows up on checking NVM version.

@morgangraphics morgangraphics self-assigned this May 24, 2020
@morgangraphics
Copy link
Owner

Ok, I've finally been able to recreate the issue. I had to download a fresh version of the role.

Let me look into it and I'll get back to you.

@DanHulton
Copy link
Contributor Author

Actually yeah, that makes sense - I only started seeing it after I did a big force-upgrade of all my libraries. Worked perfectly before that.

@morgangraphics
Copy link
Owner

morgangraphics commented May 24, 2020

Ok, I've pushed a change here 5abb5d5

You can easily test if it works by changing branches:

or by changing line 50 in the mvn.yml file from

when: (shell_path is undefined) or (found_path | bool == False)

to

when: (shell_path is undefined) or (found_path | length == 0)

If it works, let me know.

@DanHulton
Copy link
Contributor Author

Works perfectly!

@DanHulton
Copy link
Contributor Author

Also, I am stealing your practice of having a reasonably named "main" tasks file and having main.yml simply include it. Way too sick and tired of having 5 different main.yml files open and having to guess based on position which is which. =)

@morgangraphics
Copy link
Owner

Thanks for the help.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants