我们有一些脚本可以帮助我们在AWS中设置最多6个虚拟机的VPC。 现在我想登录这些机器。 出于安全原因,我们只能通过SSH访问其中一个,然后通过隧道/代理访问其他计算机。 所以在我们的库存中,我们有SSH主机的IP地址(我们称之为Redcarpet )和其他一些主机,如Elasticsearch , Mongodb和Worker :
#inventory/hosts [redcarpet] 57.44.113.25 [services] 10.0.1.2 [worker] 10.0.5.77 10.0.1.200 [elasticsearch] 10.0.5.30 [mongodb] 10.0.1.5现在我需要告诉每个组,除了redcarpet使用某些SSH设置。 如果这些适用于所有组,我会将它们放在inventory/group_vars/all.yml ,但现在我必须将它们放入:
inventory/group_vars/services.yml inventory/group_vars/worker.yml inventory/group_vars/elasticsearch.yml inventory/group_vars/mongodb.yml这会导致重复。 因此,我想使用include或include_vars来包含来自公共文件的一个或两个变量(例如inventory/common.yml )。 但是,当我尝试在上面的任何group_var文件中执行此操作时,它不会获取变量。 使用多个组共有的变量的最佳实践是什么?
We have some scripts to help us set up VPCs with up to 6 VMs in AWS. Now I want to log in to each of these machines. For security reasons we can only access one of them via SSH and then tunnel/proxy through that to the other machines. So in our inventory we have the IP address of the SSH host (we call it Redcarpet) and some other hosts like Elasticsearch, Mongodb and Worker:
#inventory/hosts [redcarpet] 57.44.113.25 [services] 10.0.1.2 [worker] 10.0.5.77 10.0.1.200 [elasticsearch] 10.0.5.30 [mongodb] 10.0.1.5Now I need to tell each of the groups, EXCEPT redcarpet to use certain SSH settings. If these were applicable to all groups, I would put them in inventory/group_vars/all.yml, but now I will have to put them in:
inventory/group_vars/services.yml inventory/group_vars/worker.yml inventory/group_vars/elasticsearch.yml inventory/group_vars/mongodb.ymlWhich leads to duplication. Therefore I would like to use an include or include_vars to include one or two variables from a common file (e.g. inventory/common.yml). However, when I try to do this in any of the group_var files above, it does not pick up the variables. What is the best practice to use with variables that are common to multiple groups?
最满意答案
如果您想使用group_vars方法,我建议您添加另一个组,并将依赖组作为子组添加到该组。
#inventory/hosts [redcarpet] 57.44.113.25 [services] 10.0.1.2 [worker] 10.0.5.77 10.0.1.200 [elasticsearch] 10.0.5.30 [mongodb] 10.0.1.5 [redcarpet_deps:children] mongodb elasticsearch worker services现在你可以拥有一个名为redcarpet_deps.yml的group_vars文件,他们应该从那里获取变量。
If you want to go with the group_vars approach, I would suggest you add another group, and add the dependent groups as children to that group.
#inventory/hosts [redcarpet] 57.44.113.25 [services] 10.0.1.2 [worker] 10.0.5.77 10.0.1.200 [elasticsearch] 10.0.5.30 [mongodb] 10.0.1.5 [redcarpet_deps:children] mongodb elasticsearch worker servicesAnd now you can have a group_vars file called redcarpet_deps.yml and they should pickup the vars from there.
更多推荐
发布评论