stephdewit/ansible-nvm

sudo

Closed this issue · 4 comments

Hi @stephdewit this query is sort of related to #4

Would it be possible to update the role so that the setup-.yml can be bypassed? This is the only place that the role contains the becomes stanza.

I'm using the role with users that don't have sudo access.

Prior to their use on the host, I can provide the dependencies that are required by this role.

Ideally having a variable nvm_install_deps or nvm_bypass_setup etc. would be great.

- include: setup-redhat.yml
  when: ansible_os_family == "RedHat" and nvm_install_deps == true
  tags: nvm

Thanks for your time.
Damian.

Hello @damianoneill

I released a new version (3.3.0) allowing to use the parameter you proposed in your example.

It will install dependencies by default, but you will now be able to bypass this. Let me know if you encounter any issues.

Thanks @stephdewit, that worked great.

It's allowed me to progress on these hosts. However, I'm now getting the following issue, when the role installs nodejs.

Interestingly after it fails, nvm is installed and I can run it directly as the non-sudo user and it works fine.

TASK [stephdewit.nvm : Install Node.js latest] *****************************************************************************************************************
task path: /usr/share/ansible/roles/stephdewit.nvm/tasks/install_nodejs.yml:10
skipping: [localhost] => {
    "changed": false,
    "skip_reason": "Conditional result was False"
}

TASK [stephdewit.nvm : Install Node.js 12.16.1] ****************************************************************************************************************
task path: /usr/share/ansible/roles/stephdewit.nvm/tasks/install_nodejs.yml:18
Using module file /usr/lib/python2.7/dist-packages/ansible/modules/commands/command.py
<127.0.0.1> ESTABLISH LOCAL CONNECTION FOR USER: doneill
<127.0.0.1> EXEC /bin/sh -c '( umask 77 && mkdir -p "` echo /tmp/.ansible/tmp/ansible-tmp-1609965570.75-175796420034855 `" && echo ansible-tmp-1609965570.75-175796420034855="` echo /tmp/.ansible/tmp/ansible-tmp-1609965570.75-175796420034855 `" ) && sleep 0'
<127.0.0.1> PUT /homes/doneill/.ansible/tmp/ansible-local-25560CVqP46/tmptgaMO7 TO /tmp/.ansible/tmp/ansible-tmp-1609965570.75-175796420034855/command.py
<127.0.0.1> EXEC /bin/sh -c 'chmod u+x /tmp/.ansible/tmp/ansible-tmp-1609965570.75-175796420034855/ /tmp/.ansible/tmp/ansible-tmp-1609965570.75-175796420034855/command.py && sleep 0'
<127.0.0.1> EXEC /bin/sh -c '/usr/bin/python2 /tmp/.ansible/tmp/ansible-tmp-1609965570.75-175796420034855/command.py && sleep 0'
<127.0.0.1> EXEC /bin/sh -c 'rm -f -r /tmp/.ansible/tmp/ansible-tmp-1609965570.75-175796420034855/ > /dev/null 2>&1 && sleep 0'
fatal: [localhost]: FAILED! => {
    "changed": true,
    "cmd": ". ./nvm.sh && nvm install 12.16.1",
    "delta": "0:00:01.307746",
    "end": "2021-01-06 12:39:32.170148",
    "invocation": {
        "module_args": {
            "_raw_params": ". ./nvm.sh && nvm install 12.16.1",
            "_uses_shell": true,
            "chdir": "/homes/doneill/.nvm",
            "creates": null,
            "executable": null,
            "removes": null,
            "stdin": null,
            "warn": true
        }
    },
    "msg": "non-zero return code",
    "rc": 1,
    "start": "2021-01-06 12:39:30.862402",
    "stderr": "mkdir: cannot create directory '/usr/bin/alias': Permission denied\nmkdir: cannot create directory '/usr/bin/alias': Permission denied\nmkdir: cannot create directory '/usr/bin/.cache': Permission denied\ncreating directory /usr/bin/.cache/bin/node-v12.16.1-linux-x64/files failed\nDownloading https://nodejs.org/dist/v12.16.1/node-v12.16.1-linux-x64.tar.xz...\nWarning: Failed to create the file \nWarning: /usr/bin/.cache/bin/node-v12.16.1-linux-x64/node-v12.16.1-linux-x64.ta\nWarning: r.xz: No such file or directory\n\ncurl: (23) Failed writing body (0 != 965)\nBinary download from https://nodejs.org/dist/v12.16.1/node-v12.16.1-linux-x64.tar.xz failed, trying source.\ngrep: /usr/bin/.cache/bin/node-v12.16.1-linux-x64/node-v12.16.1-linux-x64.tar.xz: No such file or directory\nProvided file to checksum does not exist.\nBinary download failed, trying source.\nmkdir: cannot create directory '/usr/bin/.cache': Permission denied\ncreating directory /usr/bin/.cache/src/node-v12.16.1/files failed\nDownloading https://nodejs.org/dist/v12.16.1/node-v12.16.1.tar.xz...\nWarning: Failed to create the file \nWarning: /usr/bin/.cache/src/node-v12.16.1/node-v12.16.1.tar.xz: No such file \nWarning: or directory\n\ncurl: (23) Failed writing body (0 != 967)\nBinary download from https://nodejs.org/dist/v12.16.1/node-v12.16.1.tar.xz failed, trying source.\ngrep: /usr/bin/.cache/src/node-v12.16.1/node-v12.16.1.tar.xz: No such file or directory\nProvided file to checksum does not exist.",
    "stderr_lines": [
        "mkdir: cannot create directory '/usr/bin/alias': Permission denied",
        "mkdir: cannot create directory '/usr/bin/alias': Permission denied",
        "mkdir: cannot create directory '/usr/bin/.cache': Permission denied",
        "creating directory /usr/bin/.cache/bin/node-v12.16.1-linux-x64/files failed",
        "Downloading https://nodejs.org/dist/v12.16.1/node-v12.16.1-linux-x64.tar.xz...",
        "Warning: Failed to create the file ",
        "Warning: /usr/bin/.cache/bin/node-v12.16.1-linux-x64/node-v12.16.1-linux-x64.ta",
        "Warning: r.xz: No such file or directory",
        "",
        "curl: (23) Failed writing body (0 != 965)",
        "Binary download from https://nodejs.org/dist/v12.16.1/node-v12.16.1-linux-x64.tar.xz failed, trying source.",
        "grep: /usr/bin/.cache/bin/node-v12.16.1-linux-x64/node-v12.16.1-linux-x64.tar.xz: No such file or directory",
        "Provided file to checksum does not exist.",
        "Binary download failed, trying source.",
        "mkdir: cannot create directory '/usr/bin/.cache': Permission denied",
        "creating directory /usr/bin/.cache/src/node-v12.16.1/files failed",
        "Downloading https://nodejs.org/dist/v12.16.1/node-v12.16.1.tar.xz...",
        "Warning: Failed to create the file ",
        "Warning: /usr/bin/.cache/src/node-v12.16.1/node-v12.16.1.tar.xz: No such file ",
        "Warning: or directory",
        "",
        "curl: (23) Failed writing body (0 != 967)",
        "Binary download from https://nodejs.org/dist/v12.16.1/node-v12.16.1.tar.xz failed, trying source.",
        "grep: /usr/bin/.cache/src/node-v12.16.1/node-v12.16.1.tar.xz: No such file or directory",
        "Provided file to checksum does not exist."
    ],
    "stdout": "Downloading and installing node v12.16.1...\nDetected that you have 6 CPU core(s)\nRunning with 5 threads to speed up the build",
    "stdout_lines": [
        "Downloading and installing node v12.16.1...",
        "Detected that you have 6 CPU core(s)",
        "Running with 5 threads to speed up the build"
    ]
}
	to retry, use: --limit @/usr/share/ansible/playbooks/version-managers-playbook.retry

PLAY RECAP *****************************************************************************************************************************************************
localhost                  : ok=3    changed=0    unreachable=0    failed=1

Glad it worked for you! 👍

I already saw this issue, but I'm not sure how to fix it properly. I'd recommend you to check the workaround stated in the README file (it's about setting NVM_DIR to an absolute path).

Thanks @stephdewit for the pointer.

I needed to make the directory flexible outside the playbook, the following worked for me.

NVM_DIR=/homes/doneill/.nvm ansible-playbook /usr/share/ansible/playbooks/version-managers-playbook.yml -e "ansible_remote_tmp=/tmp/.ansible/tmp"

Appreciate all your help.