如果清单仅是本地主机,则与多个组共享的ansible变量 [英] ansible variables shared with multiple groups if inventory is only localhost
问题描述
我使用ansible通过本地计算机上的kubectl命令将作业/配置发送到我的k8s集群.我已经设置了清单文件,以便每个群集都是它自己的组,并且每个群集基本上都是到localhost的连接.
I use ansible to send jobs / configurations to my k8s cluster via the kubectl command on my local machine. I have my inventory file setup so that each cluster is it's own group and each cluster is basically a connection to localhost .
# Inventory File
#
[east.k.example.com]
localhost ansible_connection=local
[east2.k.example.com]
localhost ansible_connection=local
然后在我的group_vars目录中,有一个与我的清单文件不同的文件,该文件的名称与我的清单文件相同,该文件包含每个群集的所有不同变量.
Then in my group_vars directory I have a different file with the name of my group from my inventory file that holds all the different variables for each cluster.
我使用limit选项将运行限制为仅针对一个群集:
ansible-playbook -vv create.yaml -l east2.k.example.com --tags ingress-generate-only
I limit my runs to target only one cluster with the limit option:
ansible-playbook -vv create.yaml -l east2.k.example.com --tags ingress-generate-only
问题是,当我尝试在模板中使用变量时,我从其他组中获取了变量.我在想,因为每个组都包括本地主机.
The problem is that when I attempt to use variables in my templates I get variables from the other groups. I'm thinking because each group includes localhost.
是否有更好的方法来解决此问题?我可以设置一个标志,使组仅包含group_var文件中的变量吗?
Is there a better way to solve this issue? Can I set a flag so that groups only include the variables from the group_var files?
谢谢
推荐答案
重构广告资源以使用不同的名称:
Refactor your inventory to use distinct names:
# Inventory File
#
[east.k.example.com]
east ansible_connection=local
[east2.k.example.com]
east2 ansible_connection=local
这样,Ansible会将它们视为不同的主机,因此不会合并来自不同组的变量.
This way Ansible will treat them as different hosts, thus not merging variables from different groups.
这篇关于如果清单仅是本地主机,则与多个组共享的ansible变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!