Closed ghost closed 2 years ago
There is a potential issue here which needs some clarification on your end.
- name: Create profile file if it does not exist
file:
mode: 0777
path: "{{ nvm_profile }}"
state: touch
when: not profile_file.stat.exists
become: true
The task above creates a file at the associated path {{ nvm_profile }}
with the appropriate permissions for writing to that file in the context that it is being run in. If you are getting a file not found error then the issue is where the role thinks the path is. By default we don't install as root
(unless you are running your playbook as root
user). By adding become_user: root
you essentially cement any and all zshell users to that user which overrides anyone who sets up the role like
- role: ansible-role-nvm
become: true
become_user: ubuntu
So my question is, does the user you've assigned to become_user
actually exist on the system you are running the playbook on?
I highlight this portion of the documentation (specifically the last line):
NVM Profile location Options are .bashrc, .cshrc, .tcshrc, .zshrc
nvm_profile: ".bashrc"
The location of the SHELL profile that will source the nvm command from. There are two potential contexts to consider, globally, meaning everyone who logs in will have access to nvm (which may or may not what you really want) e.g /etc/bash.bashrc, /etc/profile, etc.
OR
On a per user basis tied to a specific user account e.g. /home/vagrant/.bashrc. This role will create the appropriate profile file if it doesn't already exist.
If you specify nvm_profile: "/home/node-user/.bashrc" explicity and the node-user is not a real user on the box, then nvm will not work as you expect. become, become_user and nvm_profile path are symbiotic
The solution would be to ensure the become_user
user actually exists on the destination machine before installing NVM - https://docs.ansible.com/ansible/latest/collections/ansible/builtin/user_module.html
Thanks for the detailed answer, i now got it working by setting the full path to the .zshrc
like: nvm_profile: home/{{ user }}/.zshrc
. Anyway i might switch to another setup as it seems to be quite cumbersome to make capistrano initialize nvm during a deployment :/
Thanks for your time!
I'm trying to use the role, if i set the
become_user
the changed task fails with "file (.zshrc) is absent, cannot continue".Changing the become_user to root fixes the task.