【发布时间】:2016-07-06 16:08:10
【问题描述】:
我的问题有点棘手。我的任务是为 Ruby 中的系统构建(不是我开发的)制作部署脚本。这个项目已经有一个 capistrano 部署,只要机器有以前的设置,它就可以正常工作。我的任务是在不触及 capistrano 部分的情况下自动执行此设置。由于我对 capistrano 一无所知,也没有多少时间去做,所以我决定使用 ansible。
这个想法是运行 ansible 脚本,这会设置机器并调用 capistrano 来部署项目。我尝试了以下任务,但都产生了一些错误:
- name: Run cap
shell: "cap generic_production deploy"
environment:
MACHINE: localhost
args:
chdir: /home/{{ansible_user_id}}/project
fatal: [test]: FAILED! => {"changed": true, "cmd": "cap generic_production deploy", "delta": "0:00:00.106225", "end": "2016-07-06 15:54:42.482794", "failed": true, "rc": 1, "start": "2016-07-06 15:54:42.376569", "stderr": "/usr/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require': cannot load such file -- capistrano/setup (LoadError)
from /usr/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
from /usr/lib/ruby/vendor_ruby/capistrano/configuration/loading.rb:152:in `require'
from Capfile:2:in `load'\
from /usr/lib/ruby/vendor_ruby/capistrano/configuration/loading.rb:93:in `instance_eval'
from /usr/lib/ruby/vendor_ruby/capistrano/configuration/loading.rb:93:in `load'
from /usr/lib/ruby/vendor_ruby/capistrano/configuration/loading.rb:172:in `load_from_file'
from /usr/lib/ruby/vendor_ruby/capistrano/configuration/loading.rb:89:in `load'
from /usr/lib/ruby/vendor_ruby/capistrano/configuration/loading.rb:86:in `block in load'
from /usr/lib/ruby/vendor_ruby/capistrano/configuration/loading.rb:86:in `each'
from /usr/lib/ruby/vendor_ruby/capistrano/configuration/loading.rb:86:in `load'
from /usr/lib/ruby/vendor_ruby/capistrano/cli/execute.rb:65:in `block in load_recipes'
from /usr/lib/ruby/vendor_ruby/capistrano/cli/execute.rb:65:in `each'
from /usr/lib/ruby/vendor_ruby/capistrano/cli/execute.rb:65:in `load_recipes'
from /usr/lib/ruby/vendor_ruby/capistrano/cli/execute.rb:31:in `execute!'
from /usr/lib/ruby/vendor_ruby/capistrano/cli/execute.rb:14:in `execute'
from /usr/bin/cap:4:in `<main>'", "stdout": "", "stdout_lines": [], "warnings": []}
- name: Run cap
shell: "bundle exec cap generic_production deploy"
environment:
MACHINE: localhost
args:
chdir: /home/{{ansible_user_id}}/project
fatal: [test]: FAILED! => {"changed": true, "cmd": "bundle exec cap generic_production deploy", "delta": "0:00:00.001287", "end": "2016-07-06 15:50:21.472625", "failed": true, "rc": 127, "start": "2016-07-06 15:50:21.471338", "stderr": "/bin/sh: 1: bundle: not found", "stdout": "", "stdout_lines": [], "warnings": []}
- name: Run cap
shell: "sudo -iu {{ansible_user_id}} bundle exec cap generic_production deploy"
environment:
MACHINE: localhost
args:
chdir: /home/{{ansible_user_id}}/project
fatal: [test]: FAILED! => {"changed": true, "cmd": "sudo -iu deploy bundle exec cap generic_production deploy", "delta": "0:00:00.230098", "end": "2016-07-06 15:28:42.623268", "failed": true, "rc": 10, "start": "2016-07-06 15:28:42.393170", "stderr": "", "stdout": "Could not locate Gemfile or .bundle/ directory", "stdout_lines": ["Could not locate Gemfile or .bundle/ directory"], "warnings": ["Consider using 'become', 'become_method', and 'become_user' rather than running sudo"]}
有没有办法从 ansible 调用 capistrano 或者无法调用?
编辑: generic_production 是一个使用 MACHINE 作为目标的部署脚本。
【问题讨论】:
-
Capistrano 通常需要在本地机器上运行,而 Ansible 就是在远程机器上运行命令。你确定这是实用的吗?我不确定
MACHINE是什么,看起来不标准。 -
我认为这不实用。理想情况下,我会用 ansible 重新设计所有东西。但我没有时间做这件事,也没有时间学习如何使用 capistrano 进行设置。有没有办法让 capistrano 在本地运行?
-
我是说 Capistrano 本质上在本地运行,通过 SSH 执行远程命令。 Ansible 类似。通过 Ansible 运行 Capistrano 意味着运行...从远程服务器到远程服务器的远程命令?它们是试图完成相同工作的两种工具。
标签: ruby capistrano ansible