How to run bundle install with rvm installed using rvm1-ansible role - ruby-on-rails

I installed rvm using rv1-ansible role:
- hosts: all
remote_user: deploy
roles:
- { role: rvm_io.ruby,
tags: ruby,
rvm1_rubies: ['ruby-2.4.0'],
rvm1_user: 'deploy'
}
Now I would like to run bundle install inside application directory:
- hosts: all
remote_user: deploy
tasks:
- name: Clone git repository
git:
dest: /home/deploy/public_html/app_name
repo: git#github.com:user/app_name.git
- name: Bundle install
bundler:
state: present
chdir: /home/deploy/public_html/app_name
executable: ~/.rvm/gems/ruby-2.4.0/bin/bundle
But get error:
"/usr/bin/env: 'ruby_executable_hooks': No such file or directory"
Any idea how to do this?

You need to do a root install - installing as a specific user does not work. Little bit of info why here - Ansible is not logging in to run commands so doesn't pick up user-specific RVM stuff. By installing globally, rvm and bundler and all the other crap I don't know about which you need on the path is available on the path.
Example config installing ruby system wide ripped right from the rvm1-ansible docs:
- name: Configure servers with ruby support system wide
hosts: all
roles:
- { role: rvm_io.ruby,
tags: ruby,
become: yes,
rvm1_rubies: ['ruby-2.2.5','ruby-2.3.1'],
rvm1_install_flags: '--auto-dotfiles', # Remove --user-install from defaults
rvm1_install_path: /usr/local/rvm, # Set to system location
rvm1_user: root # Need root account to access system location
}

Related

apache, passenger/rails, ruby, redmine -- rails startup / gem path problem

I am having a ruby gem path problem starting passenger on apache.
Environment:
ubuntu-20
passenger-6.0.14
ruby-3.0.4
Ruby was installed system-wide using ruby-install, and is located at
/opt/rubies/ruby-3.0.4
chruby is being used to set the ruby environment.
ruby apps and gems are (hopefully) installed on a per-user and per-app basis. In this case, redmine is the only app.
When I visit the newly-created redmine site, passenger fails to start rails because of a gem path problem:
Raw Bundler exception:
Bundler was unable to find one of the gems defined in the Gemfile
Bundler tried to load the gems from #<struct Bundler::Settings::Path explicit_path=nil, system_path=false>
Could not find rails-6.1.4.7, rouge-3.28.0, ...
The gems are in fact, present:
$ cd ~
$ find . | grep rails-6.1.4
./.gem/ruby/3.0.4/specifications/rails-6.1.4.7.gemspec
./.gem/ruby/3.0.4/cache/rails-6.1.4.7.gem
./.gem/ruby/3.0.4/gems/rails-6.1.4.7
./.gem/ruby/3.0.4/gems/rails-6.1.4.7/README.md
The apache ssl startup for the virtual host looks like:
<IfModule mod_passenger.c>
PassengerRoot /home/test_user/.gem/ruby/3.0.4/gems/passenger-6.0.14
PassengerDefaultRuby /opt/rubies/ruby-3.0.4/bin/ruby
</IfModule>
...
Include rubies/test_user.include
and rubies/test_user.include has:
<Directory /var/www/html/issues-test>
PassengerAppRoot /home/test_user/redmine_test
PassengerAppEnv redmine_test
PassengerAppGroupName redmine_test
RailsBaseURI /issues-test
PassengerUser test_user
PassengerGroup test_user
PassengerFriendlyErrorPages on
</Directory>
The gem environment for the user where redmine is installed:
- RUBYGEMS VERSION: 3.2.33
- RUBY VERSION: 3.0.4 (2022-04-12 patchlevel 208) [x86_64-linux]
- INSTALLATION DIRECTORY: /home/test_user/.gem/ruby/3.0.4
- USER INSTALLATION DIRECTORY: /home/test_user/.gem/ruby/3.0.0
- RUBY EXECUTABLE: /opt/rubies/ruby-3.0.4/bin/ruby
- GIT EXECUTABLE: /usr/bin/git
- EXECUTABLE DIRECTORY: /home/test_user/.gem/ruby/3.0.4/bin
- SPEC CACHE DIRECTORY: /home/test_user/.local/share/gem/specs
- SYSTEM CONFIGURATION DIRECTORY: /opt/rubies/ruby-3.0.4/etc
- RUBYGEMS PLATFORMS:
- ruby
- x86_64-linux
- GEM PATHS:
- /home/test_user/.gem/ruby/3.0.4
- /opt/rubies/ruby-3.0.4/lib/ruby/gems/3.0.0
- SHELL PATH:
- /home/test_user/.gem/ruby/3.0.4/bin
- /opt/rubies/ruby-3.0.4/lib/ruby/gems/3.0.0/bin
- /opt/rubies/ruby-3.0.4/bin
- /usr/local/sbin
- /usr/local/bin
- /usr/sbin
- /usr/bin
- /sbin
- /bin
- /snap/bin
Note that the shell PATH does not include the
/home/test_user/.gem/ruby/3.0.4/gems/
path; and the test_user.include shows no path to the gems for passenger.
I'm not clear on how ruby/passenger establishes the path for gems.
The passenger install was done from the user environment.
Note: I'm also unclear as to why the INSTALLATION DIRECTORY shows
/home/test_user/.gem/ruby/3.0.4
but the USER INSTALLATION DIRECTORY shows
/home/test_user/.gem/ruby/3.0.0.
(At some point I may have done ruby-install 3.0 and it installed 3.0.4). There is, however, no directory ~/.gem/ruby/3.0.0
There were a couple of issues here. Thanks #Casper for some hints.
Passenger must be installed system-wide, i.e., as root.
It was installed as the redmine user, so had to be de-installed.
Checking the passenger uninstall page for apache, it says
"Remove the passenger files" and then details how to do that, assuming passenger was installed any way except from source.
Unfortunately, I installed from source, as the regular repositories are way out of date. Uninstalling from source is non-trivial, as the passenger files are mixed in with the other application files and there is no easy way to find them all and differentiate. I ended up deleting the entire ruby / redmine environment for the user and starting over.
To install passenger as root, in a ruby-install/chruby environment:
sudo -i
cd /opt/rubies
source /usr/local/share/chruby/chruby.sh
chruby 3.0.4
gem install passenger
passenger-install-apache2-module
exit
Once passenger was re-installed globally, attempting to set up redmine for a specific user still failed with the same error -- Bundler can't find any gems. I read several places that one should not have to set the GEM_PATH explicitly, as Passenger/Ruby/Bundler are supposed to be able to automatically find the gems they need if they are in a conventional place, but apparently not. My assumption was that since the passenger definition for the redmine app specified the user environment properly, they should be found. (It's not clear to me if this problem is specific to Passenger, an Apache2 installation, or Ruby/Bundler)
The problem may be because I am using ruby-install and not rvm; passenger's docs seem to assume rvm is used as the installer.
In any case, I had to explicitly set GEM_PATH in the apache2 configuration.
The path is the one shown if "gem env GEM_PATH" is given from the user account.
So for this case, in (file rubies/test_user.include above), add the line:
SetEnv GEM_PATH /home/test_user/.gem/ruby/3.0.4/:/opt/rubies/ruby-3.0.4/lib/ruby/gems/3.0.0/
The complete apache2 config fragment looks like:
<Directory /var/www/html/issues-test>
PassengerAppRoot /home/test_user/redmine_test
PassengerAppEnv redmine_test
PassengerAppGroupName redmine_test
RailsBaseURI /issues-test
PassengerUser test_user
PassengerGroup test_user
PassengerFriendlyErrorPages on
SetEnv GEM_PATH /home/test_user/.gem/ruby/3.0.4/:/opt/rubies/ruby-3.0.4/lib/ruby/gems/3.0.0/
</Directory>

How to resolve Rail 6 deploy error on AWS Elastic Beanstalk for ruby 2.7.1

I am trying to deploy a Rails 6 app on AWS via Elastic Beanstalk.
When I run eb deploy, it fails.
When I look at the logs, I see this message
2020/06/03 14:19:51.457403 [ERROR] rbenv: version `2.7.0' is not installed (set by /var/app/staging/.ruby-version)
2020/06/03 14:19:51.457439 [ERROR] An error occurred during execution of command [app-deploy] - [stage ruby application]. Stop running the command. Error: install dependencies in Gemfile failed with error Command /bin/sh -c bundle config set --local deployment true failed with error exit status 1. Stderr:rbenv: version `2.7.0' is not installed (set by /var/app/staging/.ruby-version)
However, when I eb ssh and run ruby -v I see that I am running ruby 2.7.1p83 (2020-03-31 revision a0c7c23c9c) [x86_64-linux]
So I updated my Gemfile and .ruby-version to ruby 2.7.1 to match my AWS environment.
When I cd /var/app/staging
and cat .ruby-version
I get 2.7.1
So why is this deploy failing? I am not requiring ruby 2.7.0 anywhere in my project.
I've made sure to git push, so I know my Gemfile is pushed my to repo.
I am going crazy trying to get this Rails App deployed.
What worked for me is to create a zip file in the root directory of your app:
zip ../rails-default.zip -r * .[^.]
https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/ruby-rails-tutorial.html
I think you can set up ruby and make it as default based on your requirement.
Just set up some config file in .ebextensions and set instructions to install ruby version you require and make it default.
e.g.
Create file in .ebextensions 00_ruby_install.config
Add content which will install ruby
files:
"/opt/elasticbeanstalk/hooks/appdeploy/pre/09_ruby_install.sh" :
mode: "000775"
owner: root
group: users
content: |
#!/usr/bin/env bash
... Add ruby install instructions here ...
there is a .ruby-version file in the root of your directory that states a different ruby version, like in your case it would be ruby-2.7.0, just change it to ruby-2.7.1 or whatever is in your Gemfile.

Add insecure rubygems source and automatically choose 'yes' for 'Do you want to add this insecure source?' (I'm using Docker-Compose)

I am provisioning an install of a node that uses some ruby gems. In order to get the gems on my corporate network I usually add 'http://rubygems.org'.
I am using Docker compose and wand to use
gem source --add http://rubygems.org, but I noticed it asks me interactively [yn].
How can I avoid the interaction, similar to apt-get install -yqq?
You can specify the gem source in ~/.gemrc file, without the interaction with the gem source command.
$> echo -e '--- \nsources:\n- http://rubygems.org/' >> ~/.gemrc
That command will generate next file:
---
sources:
- http://rubygems.org/
Which will be used by rubygems package.
Rubygems documentation

How to install Ruby on Rails on Windows?

How do I install Ruby on Rails on Windows Operating System? I am new to Ruby on Rails.
Complete Installation process and set environment on windows and set git configuration:
step 1:
Download links:
A. ruby on rails: visit http://railsinstaller.org/en
and download
B. nodejs: visit
https://nodejs.org/download/ and download
run and install railsinstaller.exe
2.run and install node.exe (optional)
step 2: set environment path:
a. go: my computer > properties
b. Then Advanced system settings
c. Then Environment Variables
d. Then Edit (here you need to edit path)
e. add C:\nodejs; to path
Test:
1. Restart your pc (optional)
2. open your terminal (Git Bash or cmd )
3. type & hit enter:
ruby -v
rails -v
git --version
node -v
if you see the versions that means everything ok.
You can Set git configuration:
$ git config --global user.name "your github username"
$ git config --global user.email email#example.com
if you want to set github ssh you can see
Generating SSH keys
if you want to install mysql and gem 'mysql2' see here
if you want to install postgresql and gem 'pg' see here

Permission denied error with RVM

I have searched for this problem and couldn't find relevant similar questions. Please bear with me if this is repetitive.
I have followed guides in RVM website to install RVM and I have installed rubies:
syed#rails:~$ rvm list
rvm rubies
ruby-1.8.7-p302 [ i386 ]
=> ruby-1.9.2-p0 [ i386 ]
As you can see I have made ruby-1.9.2 my default.
This is my gem directory:
syed#rails:~$ rvm gemdir
/home/syed/.rvm/gems/ruby-1.9.2-p0
Now, I tried to install rails and I am thrown the following error:
syed#rails:~$ gem install rails
ERROR: While executing gem ... (Errno::EACCES)
Permission denied - /home/syed/.gem/specs
I even did this without making any difference to the error:
syed#rails:~$ chown -R syed /home/syed/.rvm/
Currently, my environment looks like this:
syed#rails:~$ gem environment
RubyGems Environment:
- RUBYGEMS VERSION: 1.3.7
- RUBY VERSION: 1.9.2 (2010-08-18 patchlevel 0) [i686-linux]
- INSTALLATION DIRECTORY: /home/syed/.rvm/gems/ruby-1.9.2-p0#rails3
- RUBY EXECUTABLE: /home/syed/.rvm/rubies/ruby-1.9.2-p0/bin/ruby
- EXECUTABLE DIRECTORY: /home/syed/.rvm/gems/ruby-1.9.2-p0#rails3/bin
- RUBYGEMS PLATFORMS:
- ruby
- x86-linux
- GEM PATHS:
- /home/syed/.rvm/gems/ruby-1.9.2-p0#rails3
- /home/syed/.rvm/gems/ruby-1.9.2-p0#global
- GEM CONFIGURATION:
- :update_sources => true
- :verbose => true
- :benchmark => false
- :backtrace => false
- :bulk_threshold => 1000
- REMOTE SOURCES:
- http://rubygems.org/
I don't understand why it is trying to install gems to my system gem directory path?
I had this same problem and I resolved it by doing the following:
sudo mkdir ~/.gem/specs
sudo chmod 777 ~/.gem/specs
It seems that RVM was trying to create this "specs" folder, but didn't have permissions to do so.
I really don't like the accepted answer, its a hack not a solution suitable for production. When you chmod 777 you are giving anyone on the machine access complete access to those folders.
It is much better to create a individual gemset for that project then make sure you own it with chown.
rvm gemset create project
rvm use ruby-1.9.3-p394#project # May not be necessary
And in your gems folder, for the case above "home/syed/.rvm/gems/" make sure the new gemset you created is owned by you
cd home/syed/.rvm/gems/ && ls -la
If you don't own it then chown it to your user
sudo chown -R user:rvm gemset
Maybe try to check also the "chown" permissions for the necessary files/directories to find out more about your error message.
Usually I create gemset for the different applications/projects so I don't get a mixture of hundreds of different gems at one place after few weeks/months. Try this:
rvm use 1.9.2
rvm gemset create YOURGEMSETNAME
rvm gemset use YOURGEMSETNAME
or simply
rvm 1.9.2#YOURGEMSETNAME --create
Try to install your gems after that. If your want the gems appear for every gemset for ruby 1.9.2, than switch to the global gemset and install your gems there:
rvm 1.9.2#global
gem install rails3 # or whatever you wish
I solved this one, finally. It turns out that my firewall was blocking 199.91.171.93. When I opened access, I no longer got Errno::EACCES messages. I diagnosed this by using --verbose and I could see the source was trying to update the $HOME/.gem/specs/rubygems.org%80/quick/Marshal.4.8 area, but could not simply because the traffic was blocked.
I just had this problem and wanted to record my answer for posterity. All of the directories in my Ruby-specific RVM directory were owned by root. So I had to chown all of them.
~/.rvm/gems/ruby-1.9.3-p286
drwxr-xr-x 22 root staff 748 Nov 12 13:34 bin
drwxr-xr-x 2 root staff 68 Nov 20 14:42 cache
drwxr-xr-x 2 root staff 68 Nov 1 09:59 doc
drwxr-xr-x 47 root staff 1598 Nov 12 13:34 gems
I don't know if this is normal but after changing them all to my non-root user the problem went away.
What's your path look like? It sounds like you're getting a system version of gem instead of the rvm-based command.
For those coming from Google: On Windows I had this problem because I had an older version of Ruby installed in my Program Files directory, which newer versions of Windows have security restrictions on. Run ruby --version to make sure it is as expected.

Resources