我可以拆分我的 Capistrano capfile 吗?
我有一个 capfile,它的顶部定义了一个角色,下面有一堆任务。它工作得很好,但我希望能够轻松(并以编程方式)更新角色列表中的计算机。我知道我可以就地完成它,但为了安全起见,我希望能够将我的 capfile 分成(本质上)两个文件:主机和任务
当前(一般):
role :machines,
"machine1",
"machine2"
desc "This is task 1"
task :task1 do
# stuff
end
我希望能够类似以下内容(忽略“语法”):
role :machines ==> {Get this information from 'hosts.cap' or something}
desc "This is task 1"
task :task1 do
# stuff
end
有没有办法分解 capfile?或者我需要深入研究源代码才能做到这一点?
I've got a capfile that has a role defined at the top of it, with a bunch of tasks below. It works great, but I want to be able to easily (and programatically) update the machines in the roles list. I know I could do it in place, but to be safe, I'd like to be able to split out my capfile into (essentially) two files: hosts and tasks
Currently (generically):
role :machines,
"machine1",
"machine2"
desc "This is task 1"
task :task1 do
# stuff
end
I'd like to be able to have something like the following (ignore the "syntax"):
role :machines ==> {Get this information from 'hosts.cap' or something}
desc "This is task 1"
task :task1 do
# stuff
end
Is there a way to break the capfile up? Or would I need to dive into source to do that?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
由于 Capfile 只是 Ruby,因此您可以使用 Ruby 代码来做您想做的事情。例如,如果您的hosts.cap 文件如下所示:
您将使用以下 Ruby 代码将其放入数组中:
并正确将其交给
role
调用,请使用 splat (*) 运算符:尽管我建议将其分成两部分,因为这样更清楚:
Since a Capfile is just Ruby, you can use Ruby code to do what you want. For example, if your hosts.cap file looked like this:
you would get it in an array with this Ruby code:
and to give it to the
role
call properly, use the splat (*) operator:although I would recommend to put it in two parts, because it is clearer:
普通的
Capfile
用于随load 'config/deploy'
行一起发布 - 也许您可以利用它来加载多个文件。The vanilla
Capfile
used to ship with the lineload 'config/deploy'
- maybe you can leverage that to load multiple files.