varialbes of the remote host?
I have some executables that are in a custom directory that's not part of the default path. the .bashrc file adds it to path but since ansible is a non-login and non-interactive session it doesn't load those.
anyway to load the path for teh entire playbook?
my only solutions are:
1. sourcing the .bashrc file befre each command execution
2. using bash -lic
3. using enviroment with every task
none of these seem like a logical solution.
Why exactly do you want to read the remove env vars?
packages installed with nvm most notably npm
Please elaborate
Стикер
sure I insalled node.js via nvm, so the executable for node, npm, and npm global packages (in this case I want to use pm2) are in this path /root/.nvm/versions/node/v20.16.0/bin/ which is not part of the path var at /etc/envrioment. this path gets appended via this line in .bashrc (generated automatically by nvm) export NVM_DIR="$HOME/.nvm" [ -s "$NVM_DIR/nvm.sh" ] && \\. "$NVM_DIR/nvm.sh" # This loads nvm so now I can't access some executables without sourcing .bashrc or adding the path manually. this would be fine if I had just one play, but ansible stars a new shell in each play and the changes I made in the first play (modifying the path) is not playbook-wide.
could you eloborate a little bit?
How are you deploying it currently?
I'm not deploying the .bashrc with ansible, the remote server was instantialized before and the .bashrc was created back then. I'm might've misunderstood you
Okay, so you're ad-hoc deploying the .bashrc. Put it in Ansible instead.
err...are you installing node.js as root? WHY!?
Also this lol it sounds nightmarish to use npm instead of the package manager.
ahhh... I actually didn't know it's that bad.
This is part of your problem
I actually did this and it worked out but now I just want to know how to solve the issue of having to source some files when I use ansible. but I'm starting to realize that having to do that is the result of past mistakes.
If you had your .bashrc in Ansible you'd have no trouble as you'd already know where it's necessary.
I'm sorry I still don't understand how to go around doing this do you mean If I wanted to install node via nvm, I should've done that using ansible too? and populating my .basrc this way?
The trick is in having the entire state of the machine in the play and inventory. By ad-hoc modifying some system files, you're then running into a situation like this where you're trying to figure out to load it from the servers instead of already knowing it's there.
I think I get the gist of it, but how would I manage the version of the machine's node in my inventory/play? considering the path is depentant on the node version and it might get updated regularly and outside of this specific playbook? should I just stick to a versoin or is there a better way?
How else, ad-hoc?
yeah or some other scripts Is is just a bad approach to do stuff like this outside of this play's scope?
hey sorry to bother you again, just wanted to know my current solution is a good one or not I now store the node version and the nvm path as inventory varialbes and declare the PATH in my plays if I want to reach them. is it cool or am I doing things in a way that'll cause trouble later? how would I go about editting these variables if I had to change the node version or anyghing? ad-hoc editting the inventory?
oh got it, I'm doing this exact thing just wanted to double check if it's ok. and is storing the version and PATH as inventory group varialbes a good solution? or is there a better way to go about it.
If you install it via Ansible and symlink it you don't need to mess with variables unless you need multiple installs going.
I actually have multiple versions going for three different projects at the moment. but I'll keep it in mind to use symlinks for when I just need the one version. again. thank you!
Обсуждают сегодня