ansible variables shared with multiple groups if inventory is only localhost

旧时模样 提交于 2019-12-10 22:24:45

问题


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

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.

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.

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?

thanks,


回答1:


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

This way Ansible will treat them as different hosts, thus not merging variables from different groups.



来源:https://stackoverflow.com/questions/43504595/ansible-variables-shared-with-multiple-groups-if-inventory-is-only-localhost

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!