2016-07-06 69 views
2

我的问题有点棘手。我被赋予了一个任务,为Ruby中的系统构建(非我开发)制作部署脚本。这个项目已经有一个capistrano部署,只要机器有一个先前的设置就可以正常工作。我的任务是自动化这个设置,而不用接触capistrano部分。由于我对卡皮斯特拉诺毫无知识,并且有非常琐碎的时间来做它,我决定使用合理的。如何从脚本中调用capistrano

这个想法是运行可靠的脚本,这设置了机器并调用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作为目标。

+0

Capistrano通常需要在本地计算机上运行,​​而Ansible则是在远程计算机上运行命令。你确定这是实用的吗?我不确定'MACHINE'是什么,看起来不标准。 – tadman

+0

我不认为这是实际的。理想情况下,我会重新设计一切。但是我缺乏这方面的知识,或者无法学习如何与卡皮斯特拉诺合作。卡皮斯特拉诺有办法在当地运作吗? – joaonrb

+0

我在说Capistrano本质上运行本地,通过SSH执行远程命令。 Ansible与此类似。通过Ansible运行Capistrano意味着运行...从远程服务器到远程服务器的远程命令?他们是两种尝试做同样工作的工具。 – tadman

回答

0

这对我来说,如果从你正常运行cap从目录运行ansible playbook。

- name: capistrano deploy 
    local_action: shell cap generic_production deploy 
    become: false