# Testing whether kubectl/oc context is valid

**URL:** <https://forum.ansible.com/t/testing-whether-kubectl-oc-context-is-valid/31215>\
**Category:** Ansible Project\
**Tags:** kubernetes\
**Created:** [September 6, 2019, 11:36am UTC](https://forum.ansible.com/t/testing-whether-kubectl-oc-context-is-valid/31215 "2019-09-06T11:36:37Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![afeller](https://avatars.discourse-cdn.com/v4/letter/a/f08c70/32.png) [@afeller](https://forum.ansible.com/u/afeller)\
**Post date:** [September 6, 2019, 11:36am UTC](https://forum.ansible.com/t/testing-whether-kubectl-oc-context-is-valid/31215/1 "2019-09-06T11:36:37Z")

</div>

Does anyone have a novel way to test kubectl/oc login context explicitly in a playbook to fail instead of waiting to lower in roles?

I’m familiar with [k8s\_auth module](https://docs.ansible.com/ansible/latest/modules/k8s_auth_module.html) for handling explicit Kubernetes/OpenShift login, however there are still cases where we need to fallback on kubectl/oc context when using [k8s module](https://docs.ansible.com/ansible/latest/modules/k8s_module.html) and [k8s lookup plugin](https://docs.ansible.com/ansible/latest/plugins/lookup/k8s.html) and having a reasonable way of testing connectivity would save a lot of time…

Thanks,  
Andy
