/usr/bin/env: ruby2.1: Permission denied - ruby

fatal: [localhost]: FAILED! => {
"changed": true,
"cmd": "cd /home/username && bundle exec rake db:migrate RAILS_ENV=production",
"delta": "0:00:00.376426",
"end": "2022-08-03 12:33:57.663786",
"failed": true,
"rc": 126,
"start": "2022-08-03 12:33:57.287360",
"stderr": "Your RubyGems version (2.7.10) has a bug that prevents `required_ruby_version` from working for Bundler. Any scripts that use `gem install bundler` will break as soon as Bundler drops support for your Ruby version. Please upgrade RubyGems to avoid future breakage and silence this warning by running `gem update --system 3.2.3`\n/usr/bin/env: ruby2.1: Permission denied",
"stderr_lines": [
"Your RubyGems version (2.7.10) has a bug that prevents `required_ruby_version` from working for Bundler. Any scripts that use `gem install bundler` will break as soon as Bundler drops support for your Ruby version. Please upgrade RubyGems to avoid future breakage and silence this warning by running `gem update --system 3.2.3`",
"/usr/bin/env: ruby2.1: Permission denied"
],
"stdout": "",
"stdout_lines": []
}
What am I missing here?
[Later edit]
After going back and forth with this, installing I was able to fix it by running:
ln -s /usr/bin/ruby2.3 /usr/bin/ruby2.1

I fixed it by running:
ln -s /usr/bin/ruby2.3 /usr/bin/ruby2.1

Related

Ansible shell command doesn't seem to have access to the user's shell environment

Im trying to use a ruby installed via RBENV. I have confirmed that RBENV works as desired and produces the correct ruby version which can be called via the terminal
ruby -v returns: ruby 3.1.0p0 (2021-12-25 revision fb4df44d16) [x86_64-linux] which is the desired version
bundler -v returns: Bundler version 2.3.10 which is also the desired version.
However the following tasks in my playbook fail
- block:
- name: 'set ruby version'
shell: echo eval "$(rbenv init -)" >> ~/.zshrc
- name: 'set global ruby verison'
shell: 'rbenv global {{ ruby_version }}'
- name: 'restart shell'
shell: $shell
- name: 'Bundle install'
shell:
chdir: "{{ app_path }}"
cmd: bundle install
become: yes
become_user: '{{ deploy_user}}'
I get the following output when trying to execute these tasks in my playbook
fatal: [45.77.186.234]: FAILED! => {"changed": true, "cmd": "bundle install", "delta": "0:00:00.001967", "end": "2022-03-25 00:33:48.231712", "msg": "non-zero return code", "rc": 127, "start": "2022-03-25 00:33:48.229745", "stderr": "/bin/sh: 1: bundle: not found", "stderr_lines": ["/bin/sh: 1: bundle: not found"], "stdout": "", "stdout_lines": []}
On the docs page for ansible.builtin.shell the 3rd bullet point under synopsis indicates that the shell command is executed using the user's shell environment. I can't see anywhere that I'm supposed to define which shell specifically, I wonder if my use of ZSH is where the problem is?
At this point I've tried everything I can think of, and now Im asking for help. How do I run a shell command against the user's shell environment?
I ended up having to execute chained zsh commands to get this to work for me.
- name: Install fastlane gem
command: zsh -lc "source ~/.zshrc && gem install fastlane"
I didn't have to do this before I updated my MacOS system to 12.3.1, for what it's worth. It seems like some default behavior changed for shell execution.

VSCODE ON Monterey not working with Golang

I get the following error on vscode on Monterey with golang
Tools environment: GOPATH=/Users/randolphhill/devgo/workspace, GOBIN=/Users/randolphhill/devgo/workspace/bin
Installing 1 tool at the configured GOBIN: /Users/randolphhill/devgo/workspace/bin in module mode.
dlv
Installing github.com/go-delve/delve/cmd/dlv#latest FAILED
{
"killed": false,
"code": 2,
"signal": null,
"cmd": "/usr/local/opt/go/libexec/bin/go install -v github.com/go-delve/delve/cmd/dlv#latest",
"stdout": "",
"stderr": "go: cannot find GOROOT directory: /usr/local/opt/libexec\n"
}
1 tools failed to install.
dlv: failed to install dlv(github.com/go-delve/delve/cmd/dlv#latest): Error: Command failed: /usr/local/opt/go/libexec/bin/go install -v github.com/go-delve/delve/cmd/dlv#latest
go: cannot find GOROOT directory: /usr/local/opt/libexec
That seems like an odd GOROOT path. Have you tried uninstalling and reinstalling Go?
I have go installed and it is located at /usr/local/go/bin/go not /usr/local/opt/go/libexec/bin/go.
From the Go website: https://go.dev/doc/manage-install; The default install location is usually /usr/local/go.

Why doesn't gem install fpm via ansible?

I have created an EC2 instance on Amazon Cloud and I am installing some stuffs via ansible too. But when it installs fpm using gem:
- name: install fpm
gem: name=fpm state=latest
sudo: yes
it says:
changed: [XX.XX.XXX.XXX] => {"changed": true, "name": "fpm", "state": "latest", "version": "1.3.3"}
No errors. But when I enter the instance and try to run a script it says:
fpm is mandatory, please run gem install fpm
If I do sudo gem install fpm in console of the EC2, the script runs as espected.
So what am I doing wrong? Doesn't Ansible install the fpm?
I have fixed the problem by doing
- name: install fpm
command: bash -lc "gem install fpm"
instead of
- name: install fpm
gem: name=fpm state=latest
sudo: yes
Now It does not ask for fpm anymore, it is installed. But why gem does not work?

Ansible "Permission denied" when trying to install/check a gem

I recently decided to switch my Ansible deployment to install Ruby via rbenv rather than from apt-get via ruby1.9.1. Now I'm getting an error when trying to install the gem via Ansible.
TASK: [nginx | s3cp gem] ******************************************************
failed: [staging.myapp.com] => {"cmd": ["/usr/local/bin", "query", "-n", "^s3cp$"], "failed": true, "item": "", "rc": 13}
msg: [Errno 13] Permission denied
FATAL: all hosts have already failed -- aborting
Ansible playbook entry for this command:
- name: s3cp gem
gem: name=s3cp state=present executable=/usr/local/bin
I have sudo set to "yes" in a higher-level call to this playbook part. So I am not sure why it's tripping up. I also am able to login with the same user used for Ansible and navigate to that directory and also install this gem.
It was working fine when I was using apt-get to install ruby1.9.1. Any ideas?
This is deployed to an Ubuntu 13.04 server, by the way.
MORE INFORMATION:
Apparently it's not just tripping up on s3cp. I skipped that one and went on to another command to install bundler. This command also would not work (failed in the same way). I am wondering if there's a default ruby that's conflicting with the rbenv ruby (though, which ruby when ssh'ed in is yielding the expected rbenv directory).
MORE-MORE INFO:
I tried to install ruby via rvm instead. I had the same error. :(
What happens when you run ansible with -vvvv? It should provide full verbose output of the tasks, hopefully including any errors that it encounters. With a bit of luck it will show you what the problem is.
Another thing to check is what user you're running the tasks as. How do you have the following parameters set at the top of your play (or do you not specify any of these)?
- hosts: myhosts
user: someuser
sudo: True
sudo_user: another_user
As far as I know, the gem ansible module is not rbenv-aware. This means that when you call the gem module, it will try to install a gem system wide. This, of course, will fail if you're not acting as root on your node.
To install a gem with rbenv, you must use rbenv's gem shim. The only way to do this is to be able to trigger rbenv init by sending the command thru bash :
- name: Install Bundler
command: bash -lc "gem install bundler"
This has been already adressed here :
Install Bundler gem using Ansible

json gem install error on bundle install

When I try to do a bundle install I get the following json error. The bundle install does not complete. What gives?
Errno::EACCES: Permission denied - /usr/local/Cellar/ruby/1.9.3-p194/lib/ruby/gems/1.9.1/gems/json-1.7.5/.gitignore
An error occurred while installing json (1.7.5), and Bundler cannot continue.
Make sure that `gem install json -v '1.7.5'` succeeds before bundling.
>>$ gem install json -v '1.7.5'
ERROR: While executing gem ... (Errno::EACCES)
Permission denied - /usr/local/Cellar/ruby/1.9.3-p194/lib/ruby/gems/1.9.1/gems/json-1.7.5/.gitignore
EDIT: The sudo install command gives the following error:
>>$ sudo gem install json -v '1.7.5'
Building native extensions. This could take a while...
ERROR: Error installing json:
ERROR: Failed to build gem native extension.
/usr/local/Cellar/ruby/1.9.3-p194/bin/ruby extconf.rb
creating Makefile
make
sh: make: command not found
Gem files will remain installed in /usr/local/Cellar/ruby/1.9.3-p194/lib/ruby/gems/1.9.1/gems/json-1.7.5 for inspection.
Results logged to /usr/local/Cellar/ruby/1.9.3-p194/lib/ruby/gems/1.9.1/gems/json-1.7.5/ext/json/ext/generator/gem_make.out
you need to install ruby1.8-dev and not just ruby1.8, you are missing the development headers.
if on OSX:
sudo install ruby1.8-dev
if on unix
sudo aptitude install ruby1.8-dev
or
sudo apt-get install ruby1.8-dev
go into your directory with rubygems source and run:
sudo ruby setup.rb
after that run:
if on OSX:
sudo gem install json -v '1.7.5'
some unix system may need gem version command to work properly so you should run:
sudo gem1.8 install json -v '1.7.5'
Try using this script
sudo chown -R $USER /usr/local
Found the answer here: "sh: make: command not found" when running "$ bundle" after adding redcarpet gem to Rails app Needed to upgrade command line tools after installing Mountain Lion

Resources