Comments (9)
Not saying this is necessarily the right solution, but it's the one I came up with messing with rbenv on my own a while ago, and it's been working fine for me:
- name: source rbenv init in non-interactive shells
lineinfile: dest=/etc/bash.bashrc
state=present
regexp='profile.d/rbenv.sh'
insertbefore=BOF
line="source /etc/profile.d/rbenv.sh"
from rbenv.
ssh [email protected] -t "bash -lc 'ruby -v'"
ruby 2.2.2p95
from rbenv.
Thanks zzet, if I recall any shell
commands are run non-interactively. Any tips?
from rbenv.
@dmitrym0 Sorry, can you explain your question?
from rbenv.
@zzet, I'm trying to provision an environment from an ansible script. Specifically it requires installing ruby 2.2.2 and Phusion Passenger. I have the following statement:
- name: install passenger
shell: gem install passenger
Unfortunately that will run into an issue because it will try to use system ruby (which happens to be 1.9.3 on ubuntu 12.04) because shims aren't loaded for non-interactive shells.
As a work around, I'm specifying that sudo needs to be executed with the -i
flag (I found it in another github ansible discussion).
- name: install passenger
shell: gem install passenger
sudo_user: "{{ deployment_user }} -i"
I suppose it works fine, but I do have to add this stanza to every shell
invocation. Is this something you're doing as well? How are you using custom ruby versions in your playbooks?
from rbenv.
I am writing here as the other two issues are closed. I see your point in #9240 but the case is that one could setup user shell and only then use shell
with expected profile configuration. Other users have described use cases involving rvm
and other tools that can be installed on different places but ultimately are responsible to setup user environment in a way that particular commands are available.
It is in fact more error prone to hardcode things that these tools do as if the tool changes, or some version number changes, then strings would need to be updated on a number of places. And it will be very ugly for example to invoke a rvm
installation of ruby without the help of the profile scripts. Also it affects re-usability on different systems where shell is configured to hide the differences for particular plays (e.g. solaris vs linux).
It is totally ok to warn users when doing something but I can't understand why prevent user do something when it makes sense even if that often doesn't make sense. Stupid user will always find a way to do stupid things. But preventing legitimate use cases is more harmful IMO.
P.S. script
module as suggested in one of the issues is really an overkill for simple one-line commands. Not only an overkill but also makes playbook harder to understand.
from rbenv.
came here from ansible/ansible#4854 - to repeat what I said there, I have to wrap my commands in an additional bash -lc
like: shell: bash -lc "gem install passenger"
which will get the environment initialized correctly. Not pretty, but it works. I suppose you could also change that to command: /bin/bash -lc "gem whatever"
if you want to remove one level of "shell inception."
@akostadinov I read your comment a couple times but I'm not sure I understand what you're proposing as a solution. [My comment on 4854] has a more complete example in the context of nodejs/NVM but the issue is exactly the same. I don't actually think this is an issue with rbenv and I think @zzet may be limited as to how much exactly can be solved in this role, vs solving it in either the core shell
module or by adding an interactive
option to the ansible sudo directive.
from rbenv.
@thom-nic , good point, I didn't state my proposed solution. In fact I can't think of a common use case where shell profile files are better not loaded. And I can't think of such. If machine was setup by ansible and then maintained by ansible, then shell and profile scripts should be pretty much solid. Is it a common use case to run ansible over some random machine that you are not well aware of it's current setup? I hope not.
So the solution IMO is to enable login shell by default and allow disabling that. I'm ok if at least login shell can be enabled somehow (shell module option or sudo directive).
from rbenv.
I agree, but don't know of a good solution to enable login profile by default. The discussion in the ansible issue I linked above has a couple proposed solutions but none that song require a change to ansible core.
As I commented on that issue, the best solution I've come up with is to use shell: bash -LC "some command with login env"
but that's not exactly pretty.
from rbenv.
Related Issues (20)
- Multiuser install triggers a "sudo: password is required" HOT 1
- No package matching 'libyaml-devel' found available, installed or updated HOT 1
- always reports "changed"
- Fails on Debian Stretch due to permissions HOT 2
- ruby cleanup fails HOT 1
- the curl utility itself is a rbenv build dependency, and isn't always there already HOT 1
- No idempotency on "install ruby versions for system" HOT 1
- Bundler 2.0 compatibility HOT 3
- Build fails on Ubuntu 18 Bionic Beaver HOT 1
- Why some important tasks are marked to ignore_errors ? HOT 2
- error Install with env user at task: initialization to profile system-wide
- Role works on Ubuntu only
- zzet.rbenv missing on ansible galaxy HOT 1
- Use a mirror to download/install ruby? HOT 1
- The primary branch on rbenv/rbenv-installer repo has been changed to 'main' from 'master'
- fail to run through ansible 2.11, python version 3.8.5
- The error was: 'dict object' has no attribute 'drop_ruby' HOT 2
- Plugins step fails because rbenv-installer removed the master branch HOT 2
- "No package matching 'libjemalloc1' is available" HOT 1
- Plugin installation is unexpectedly skipped
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from rbenv.