Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How can I use kubernetes.core.kubectl connection to connect to the Supervisor of a VMware TKG cluster? #673

Open
mbx64 opened this issue Jan 25, 2024 · 3 comments
Labels
type/enhancement New feature or request

Comments

@mbx64
Copy link

mbx64 commented Jan 25, 2024

SUMMARY

When connecting to the Supervisor of a VMware TKG cluster, you have to use the following command manually:

kubectl vsphere login --server=<KUBERNETES-CONTROL-PLANE-IP-ADDRESS> --vsphere-username <VCENTER-SSO-USER>

After that, I have a kubeconfig file with which I can connect to my cluster with the modules of this collection. But is there a way I can pass arguments to the kubernetes.core.kubectl connection module, so that I can directly connect to my cluster, without executing kubectl vsphere login beforehand?

ISSUE TYPE
  • Documentation Report
COMPONENT NAME

kubectl

ANSIBLE VERSION
nsible [core 2.15.8]
  config file = /home/user/.ansible.cfg
  configured module search path = ['/home/user/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /home/user/.local/lib/python3.9/site-packages/ansible
  ansible collection location = /home/user/.ansible/collections:/usr/share/ansible/collections
  executable location = /home/user/.local/bin/ansible
  python version = 3.9.17 (main, Aug 10 2023, 15:11:31) [GCC 8.5.0 20210514 (Red Hat 8.5.0-20)] (/usr/bin/python3)
  jinja version = 3.1.3
  libyaml = True
@gravesm
Copy link
Member

gravesm commented Apr 18, 2024

This is not something the connection plugin supports.

@gravesm gravesm added the type/enhancement New feature or request label Apr 18, 2024
@yurnov
Copy link
Contributor

yurnov commented Apr 18, 2024

Hi @mbx64, did you try to do something like:

---
- hosts: localhost connection=local 
  gather_facts: no
  tasks: 
  - name: login to VMware TKG cluster
    ansible.builtin.shell: "kubectl vsphere login --server={{ vcenter-address }}  --vsphere-username {{ VCENTER-SSO-USER }}"

- hosts: localhost
  gather_facts: no
  gather_facts: no
  any_errors_fatal: yes
  vars:
    ansible_connection: "kubernetes.core.kubectl"
    ansible_kubectl_namespace: "test"
    ansible_kubectl_config: "{{ ansible_user_dir }}/.kube/config"
....

@mbx64
Copy link
Author

mbx64 commented Apr 23, 2024

@yurnov Yes, that's almost what I am currently doing. You also have to add the KUBECTL_VSPHERE_PASSWORD environment variable to your first play. Your second play is not needed. You can directly call kubernetes.core.k8s in your first play as a second task. E. g.:

- hosts: vcenter
  connection: local
  gather_facts: false
  tasks:

    - name: Login to VMware TKG cluster
      environment:
        KUBECTL_VSPHERE_PASSWORD: '{{ ansible_password }}'
      ansible.builtin.shell: |
        kubectl vsphere login --server={{ control_plane }} --vsphere-username {{ ansible_user }}

    - name: Apply a config
      kubernetes.core.k8s:
        context: my_context
        definition: ...

    - name: Logout from VMware TKG cluster
      ansible.builtin.shell: |
        kubectl vsphere logout

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type/enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants