geerlingguy / ansible-role-nodejs

Ansible Role - Node.js
https://galaxy.ansible.com/geerlingguy/nodejs/
MIT License
410 stars 252 forks source link

Set nodejs_install_npm_user to ansible_user_id #75

Closed hakamine closed 4 years ago

hakamine commented 6 years ago

Recent ansible releases seem to use ansible_user_id instead of ansible_user. Set nodejs_install_npm_user to ansible_user_id if it exists.

hakamine commented 6 years ago

Some background: having problems with the default('env', 'USER')) assignment, it causes an error when the user in the ansible target machine is different from the one in the control machine (#66)

khafatech commented 6 years ago

Any reason why this isn't merged yet?

With this change, there are four precedences for the "user". The highest priority is first:

  1. nodejs_install_npm_user
  2. ansible_user_id
  3. ansible_user
  4. $USER

This means, for instance, that nodejs_install_npm_user will be used, if defined, regardless of other variables. If it's not defined, ansible checks to see if ansible_user_id is defined, and so on.

Maybe combine the two tasks that set nodejs_install_npm_user into one task? The two tasks are equivalent to: Edit: fixed syntax

- name: Define nodejs_install_npm_user
  set_fact:
    nodejs_install_npm_user: "{{ ansible_user_id | default(ansible_user) | default(lookup('env', 'USER')) }}"
  when: nodejs_install_npm_user is not defined
stale[bot] commented 4 years ago

This pull request has been marked 'stale' due to lack of recent activity. If there is no further activity, the PR will be closed in another 30 days. Thank you for your contribution!

Please read this blog post to see the reasons why I mark pull requests as stale.

stale[bot] commented 4 years ago

This pull request has been closed due to inactivity. If you feel this is in error, please reopen the pull request or file a new PR with the relevant details.

gretel commented 3 years ago

this is still relevant and very confusing. please merge the fix.

kayue commented 3 years ago

Run into the same problem here when using Packer

kayue commented 3 years ago

Fixed this by defining a var

vars:
  nodejs_install_npm_user: "{{ ansible_user_id }}"