使用Ansible安装Bundler gem [英] Install Bundler gem using Ansible
问题描述
我已经安装了rbenv,全局ruby是2.1.0。
如果我以root用户身份进入服务器并运行 gem install bundler
,它将完美安装。
我尝试了以下三种使用Ansible安装Bundler gem的方法,并且所有这三种方式都不会产生错误,但是当我SSH进入并运行 gem list
,Bundler无处可见。
尝试1:
---
- name:安装Bundler
shell:gem install bundler
尝试2:
---
- name:安装Bundler
shell:gem install bundler
尝试3:
---
- name:安装Bundler
gem:name = bundler
state = latest
我也尝试了最后一次使用 user_install = yes
和 user_install = no
并且没有任何区别。
任何想法如何通过Ansible正确安装Bundler?
我已经在这里工作了一段时间,并安装了1个ruby版本:2.1.0和ahve发现rbenv的shim目录没有包含 bundle
。
对于 bundle 在那里?我只是感到困惑,因为当我运行
sudo gem list
时,为什么capistrano找不到 bundle
命令,但不是当我运行 gem list
?
root @ weepingangel:/ usr / local / rbenv / shims#echo $ PATH
/ usr / local / rbenv / shims:/ usr / local / sbin:/ usr / local / bin:/ usr / sbin:/ usr / bin:/ sbin :/ bin:/ usr / games
root @ weepingangel:/ usr / local / rbenv / shims#gem environment
RubyGems环境:
- RUBYGEMS VERSION:2.2.0
- RUBY VERSION:2.1.0(2013-12-25 patchlevel 0)[x86_64-linux]
- 安装目录:/usr/local/rbenv/versions/2.1.0/lib/ruby/gems/2.1.0
- RUBY EXECUTABLE:/usr/local/rbenv/versions/2.1.0/bin/ruby
- 可执行目录:/usr/local/rbenv/versions/2.1.0/bin
- SPEC CACHE DIRECTORY:/root/.gem/specs
- RUBYGEMS平台:
- ruby
- x86_64-linux
- 创业板路径:
- / usr / local / rbenv / versions / 2.1.0 / lib / ruby / gems / 2.1.0
- / root /.gem/ruby/2.1.0
- 创业板配置:
- :update_sources => true
- :verbose => true
- :backtrace => false
- :bulk_threshold => 1000
- :sources => [http://gems.rubyforge.org,http://gems.github.com]
- gem=> --no-ri --no-rdoc
- 远程源:
- http://gems.rubyforge.org
- http://gems.github.com
- SHELL PATH:
- /usr/local/rbenv/versions/2.1.0/bin
- / usr / local / rbenv / libexec
- / usr / local / rbenv / shims
- / usr / local / sbin
- / usr / local / bin
- / usr / sbin
- / usr / bin
- / sbin
- / bin
- / usr / games
任何想法?
所以,我认为我有两个主要问题:
-
为什么bundler只有当我运行
sudo gem list
? 时才可见。 -
我的部署说:
INFO [18d5838c]正在运行/ usr / bin / env bundle install --binstubs
/ var / rails_apps / neiltonge / shared / bin - -path
/ var / rails_apps / neiltonge / shared / bundle --without development test
--deployment --quiet on 188.226.159.96 DEBUG [18d5838c]命令:cd / var / rails_apps / neiltonge / releases / 20140301205432&安培;&安培; (PATH = $ PATH
/ usr / bin / env bundle install --binstubs
/ var / rails_apps / neiltonge / shared / bin --path
/ var / rails_apps / neiltonge / shared / bundle - 没有开发测试
--deployment --quiet)DEBUG [18d5838c] / usr / bin / env:bundle:没有这样的文件或目录
,这是我的
$ PATH
:
的/ usr /本地/ rbenv /垫片:在/ usr / local / sbin中:在/ usr / local / bin中:/ usr / sbin目录:在/ usr / bin中:/ sbin目录:/ bin中:在/ usr /游戏
为什么不能定位?
问题在于,当通过ansible运行 gem install bundler
,因为 rbenv init
在 .bashrc
或中运行,所以您没有正确初始化rbenv。 .bash_profile中
。因此,所使用的 gem
命令是系统命令,而不是作为rbenv shim安装的命令。因此,无论何时安装gem,它都安装在系统范围内,而不是安装在rbenv环境中。
要让rbenv正确初始化,必须自己执行bash并明确声明它是一个登录shell,所以它读取它的初始化文件:
ansible your_host -m命令-a'bash -lcgem install <-u your_rbenv_user
保留 -u your_rbenv_user
部分如果你真的想这样做的根。
如果上述命令的作品,你可以很容易地把它变成一个剧本行动:
- name:安装Bundler
sudo_user:your_rbenv_user
命令:bash -lcgem install bundler
这很麻烦,但这是我目前找到的唯一方法。
I am trying to install Bundler on my VPS using Ansible.
I already have rbenv set up and the global ruby is 2.1.0.
If I SSH as root into the server and run gem install bundler
, it installs perfectly.
I have tried the following three ways of using Ansible to install the Bundler gem and all three produce no errors, but when I SSH in and run gem list
, Bundler is nowhere to be seen.
Attempt 1:
---
- name: Install Bundler
shell: gem install bundler
Attempt 2:
---
- name: Install Bundler
shell: gem install bundler
Attempt 3:
---
- name: Install Bundler
gem: name=bundler
state=latest
I have also tried the last attempt with user_install=yes
and also with user_install=no
and neither make any difference.
Any ideas how I can get it to install Bundler correctly via Ansible?
I've been working on this for a little while now and I have 1 ruby version installed: 2.1.0 and ahve found that the shims directory for rbenv does not contain a shim for bundle
.
Should a shim for bundle
be in there? I'm just getting confused as to why capistrano cannot find the bundle
command as it's listed when I run sudo gem list
but NOT when I run gem list
?
root@weepingangel:/usr/local/rbenv/shims# echo $PATH
/usr/local/rbenv/shims:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games
root@weepingangel:/usr/local/rbenv/shims# gem environment
RubyGems Environment:
- RUBYGEMS VERSION: 2.2.0
- RUBY VERSION: 2.1.0 (2013-12-25 patchlevel 0) [x86_64-linux]
- INSTALLATION DIRECTORY: /usr/local/rbenv/versions/2.1.0/lib/ruby/gems/2.1.0
- RUBY EXECUTABLE: /usr/local/rbenv/versions/2.1.0/bin/ruby
- EXECUTABLE DIRECTORY: /usr/local/rbenv/versions/2.1.0/bin
- SPEC CACHE DIRECTORY: /root/.gem/specs
- RUBYGEMS PLATFORMS:
- ruby
- x86_64-linux
- GEM PATHS:
- /usr/local/rbenv/versions/2.1.0/lib/ruby/gems/2.1.0
- /root/.gem/ruby/2.1.0
- GEM CONFIGURATION:
- :update_sources => true
- :verbose => true
- :backtrace => false
- :bulk_threshold => 1000
- :sources => ["http://gems.rubyforge.org", "http://gems.github.com"]
- "gem" => "--no-ri --no-rdoc"
- REMOTE SOURCES:
- http://gems.rubyforge.org
- http://gems.github.com
- SHELL PATH:
- /usr/local/rbenv/versions/2.1.0/bin
- /usr/local/rbenv/libexec
- /usr/local/rbenv/shims
- /usr/local/sbin
- /usr/local/bin
- /usr/sbin
- /usr/bin
- /sbin
- /bin
- /usr/games
Any ideas?
So, I think the two main problems I have:
Why is bundler only visible when I run
sudo gem list
?My deploy is saying:
INFO [18d5838c] Running /usr/bin/env bundle install --binstubs /var/rails_apps/neiltonge/shared/bin --path /var/rails_apps/neiltonge/shared/bundle --without development test --deployment --quiet on 188.226.159.96 DEBUG [18d5838c] Command: cd /var/rails_apps/neiltonge/releases/20140301205432 && ( PATH=$PATH /usr/bin/env bundle install --binstubs /var/rails_apps/neiltonge/shared/bin --path /var/rails_apps/neiltonge/shared/bundle --without development test --deployment --quiet ) DEBUG [18d5838c] /usr/bin/env: bundle: No such file or directory
and this is my
$PATH
:/usr/local/rbenv/shims:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games
Why can't bundle be located?
The problem is that, when running gem install bundler
via ansible, you're not initializing rbenv properly, since rbenv init
is run in .bashrc
or .bash_profile
. So the gem
command used is the system one, not the one installed as a rbenv shim. So whenever you install a gem, it is installed system-wide, not in your rbenv environment.
To have rbenv initialized properly, you must execute bash itself and explicitely state that it's a login shell, so it reads it's initialization files :
ansible your_host -m command -a 'bash -lc "gem install bundler"' -u your_rbenv_user
Leave the -u your_rbenv_user
part if you really want to do this as root.
If the above command works, you can easily turn it into a playbook action :
- name: Install Bundler
sudo_user: your_rbenv_user
command: bash -lc "gem install bundler"
It's cumbersome, but it's the only way I found so far.
这篇关于使用Ansible安装Bundler gem的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!