使用capistrano进行部署时,我想访问yml
模板文件中的当前主机/远程计算机角色。
我尝试过的事情
我尝试进行实验以查看是否有一个host
变量可用,但似乎没有任何作用。
$CAPISTRANO:HOST$
似乎适用于较早版本的capistrano。如何在模板化的yaml文件中执行类似此伪代码的操作?
production:
app_name: <%= TODO: IF HOST A/b/c -- App 1. If host Z -- app 2 %>
答案 0 :(得分:0)
From what I understand, I have handled a similar problem programatically.
As you may know for each environment there is a .rb file in the config/deploy/ directory.
In our problem, we had a YAML file that had host and role information, viz. below:
A:
- web
- db
- mongo
B:
- web
- app
To apply this role specific to each host, we iterated over this YAML file (ruby has easy to follow instructions on that) and added a line of code. Here is the psuedocode:
for host in HOST_LIST_YAML do
for role in ROLE_LIST do
role :role, %w{USER@host}
end
end
Here, all the role mappings are applied to the hosts. Similarly, you can write this code on your environment.rb file.