ruby – 如何从Ansible安装passenger-nginx?

我正在尝试使用Ansible 1.4.1在Ubuntu 12.04上使用nginx运行乘客Web服务器的安装.似乎gem安装正在搞乱或者其他什么,因为ansible找不到命令,当我重新安装时宝石手工制作.我究竟做错了什么?# ruby.yml- name: instal...

我正在尝试使用Ansible 1.4.1在Ubuntu 12.04上使用nginx运行乘客Web服务器的安装.似乎gem安装正在搞乱或者其他什么,因为ansible找不到命令,当我重新安装时宝石手工制作.我究竟做错了什么?

# ruby.yml

- name: "install ruby"
  script: scripts/install_ruby.sh

- name: "Install bundler"
  gem: name=bundler state=latest

- name: "Install passenger"
  gem: name=passenger state=latest

- name: "Copy nginx upstart"
  copy: src=nginx.conf dest=/etc/init/nginx.conf mode=0644 owner=root group=root

- name: Install passenger-nginx
  command: passenger-install-nginx-module --auto-download --auto --prefix=/opt/nginx --extra-configure-flags='--with-http_gzip_static_module --with-http_secure_link_module --with-http_realip_module --with-http_ssl_module' creates=/opt/nginx

- name: "Enable Nginx"
  service: name=nginx state=started enabled=yes

错误:

TASK: [common | install ruby] *************************************************
changed: [staging-2.coinvalley.com]

TASK: [common | Install bundler] **********************************************
ok: [staging-2.coinvalley.com]

TASK: [common | Install passenger] ********************************************
ok: [staging-2.coinvalley.com]

TASK: [common | Copy nginx upstart] *******************************************
ok: [staging-2.coinvalley.com]

TASK: [common | Install passenger-nginx] **************************************
failed: [staging-2.coinvalley.com] => {"cmd": ["passenger-install-nginx-module", "--auto-download", "--auto", "--prefix=/opt/nginx", "--extra-configure-flags=--with-http_gzip_static_module --with-http_secure_link_module --with-http_realip_module --with-http_ssl_module"], "failed": true, "item": "", "rc": 2}
msg: [Errno 2] No such file or directory

FATAL: all hosts have already failed -- aborting

当我进去时,我看到宝石存在:

root @staging-2:?#gem list

*** LOCAL GEMS ***

bigdecimal (1.2.3)
bundler (1.5.2)
daemon_controller (1.1.8)
io-console (0.4.2)
json (1.8.1)
minitest (4.7.5)
passenger (4.0.36)
psych (2.0.2)
rack (1.5.2)
rake (10.1.0)
rdoc (4.1.0)
test-unit (2.1.0.0)

但是,当我尝试运行install命令时,它仍然无法正常工作:

root@staging-2:~# passenger-install-nginx-module
passenger-install-nginx-module: command not found

它只有在重新运行时才有效:

gem install passenger

Ruby是从源代码安装的,这是我的gem env

root@staging-2:~# gem env
RubyGems Environment:
  - RUBYGEMS VERSION: 2.2.0
  - RUBY VERSION: 2.1.0 (2013-12-25 patchlevel 0) [x86_64-linux]
  - INSTALLATION DIRECTORY: /usr/local/lib/ruby/gems/2.1.0
  - RUBY EXECUTABLE: /usr/local/bin/ruby
  - EXECUTABLE DIRECTORY: /usr/local/bin
  - SPEC CACHE DIRECTORY: /root/.gem/specs
  - RUBYGEMS PLATFORMS:
    - ruby
    - x86_64-linux
  - GEM PATHS:
     - /usr/local/lib/ruby/gems/2.1.0
     - /root/.gem/ruby/2.1.0
  - GEM CONFIGURATION:
     - :update_sources => true
     - :verbose => true
     - :backtrace => false
     - :bulk_threshold => 1000
  - REMOTE SOURCES:
     - https://rubygems.org/
  - SHELL PATH:
     - /usr/local/sbin
     - /usr/local/bin
     - /usr/sbin
     - /usr/bin
     - /sbin
     - /bin
     - /usr/games

我看到GEM PATH目录中的可执行文件:

- /root/.gem/ruby/2.1.0

但显然这不会被添加到主要路径?

Ansible的gem模块可以在幕后使用–user-install option吗?

好吧,显然它是:http://docs.ansible.com/gem_module.html#gem-manage-ruby-gems

留下问题供其他人参考

解决方法:

因为你在Ubuntu上,只需使用Ansible通过apt-get安装the Phusion Passenger Debian packages(点击“Ubuntu”).它与apt-getting其他任何东西完全相同,比使用RubyGems安装要容易得多,甚至为你安装所有必需的依赖项(包括Ruby本身!)

本文标题为:ruby – 如何从Ansible安装passenger-nginx?