# kubectl multiple clusters how to best handle inventory.

**URL:** <https://forum.ansible.com/t/kubectl-multiple-clusters-how-to-best-handle-inventory/23956>\
**Category:** Ansible Project\
**Tags:** kubernetes\
**Created:** [March 13, 2017, 7:58pm UTC](https://forum.ansible.com/t/kubectl-multiple-clusters-how-to-best-handle-inventory/23956 "2017-03-13T19:58:32Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Matt\_Snoby1](https://avatars.discourse-cdn.com/v4/letter/m/ecd19e/32.png) [@Matt\_Snoby1](https://forum.ansible.com/u/Matt_Snoby1)\
**Post date:** [March 13, 2017, 7:58pm UTC](https://forum.ansible.com/t/kubectl-multiple-clusters-how-to-best-handle-inventory/23956/1 "2017-03-13T19:58:32Z")

</div>

Hi All,  
I need some suggestions, I have an Ansible project that I use to deploy Kubernetes with KOPS. The inventory file is very simple

`[targets] localhost ansible_connection=local`

I also use this project to add additional functionality to my clusters with for instance the dashboard docker file. Basically it looks like:

`

- name: Add Kubernetes dashboard deployment configuration  
template:  
src: kubernetes-dashboard.yaml.j2  
dest: /tmp/kubernetes-dashboard.yaml  
mode: 0644  
become: false

- name: Launch Kubernetes dashboard service  
command: “kubectl create -f /tmp/kubernetes-dashboard.yaml”  
`

However I was thinking it would be better if I could pass a context into the kubectl command like cluster [foo.east.example.com](http://foo.east.example.com) or [foo.west.example.com](http://foo.west.example.com). This is all supported already in kubectl like this:

- name: Launch Kubernetes dashboard service  
command: “kubectl --context=[foo.east.example.com](http://foo.east.example.com) create -f /tmp/kubernetes-dashboard.yaml”

What I’m not sure about is how I can setup my inventory file to perhaps have variables such as the cluster name. For instance could I do something like

`  
[[foo.east.example.com](http://foo.east.example.com)]  
localhost ansible\_connection=local

[[foo.west.example.com](http://foo.west.example.com)]  
localhost ansible\_connection=local  
`

And then setup a group/foo.east.example.com.yaml file and put my variables in there for that cluster and do the same for a group/foo.west.example.com/yaml file ?  
Is that a best practices way to do it?

Thanks for any insight you can provide!  
Matt
