kubernetes.core icon indicating copy to clipboard operation
kubernetes.core copied to clipboard

kubernetes.core.k8s looking for kubeconfig on Ansible Controller

Open nafey1 opened this issue 2 years ago • 1 comments

I am running my ansible playbook using the command below, and it is essentially looking for the kubeconfig file on the Ansible controller server, however I have the kubeconfig file place on the target machine

ansible-playbook -i 192.189.148.112, -e 'remotehost=192.189.148.112'  oke.yml

PLAY [192.189.148.112] **********************************************************************************************************************************************************

TASK [Ensure the myapp Namespace exists.] ************************************************************************************************************************************** An exception occurred during task execution. To see the full traceback, use -vvv. The error was: If you are using a module and expect the file to exist on the remote, see the remote_src option fatal: [192.189.148.112]: FAILED! => {"changed": false, "msg": "Could not find or access '/home/opc/.kube/config' on the Ansible Controller.\nIf you are using a module and expect the file to exist on the remote, see the remote_src option"}

PLAY RECAP ********************************************************************************************************************************************************************* 192.189.148.112 : ok=0 changed=0 unreachable=0 failed=1 skipped=0 rescued=0 ignored=0

My Ansible playbook is:

---
- hosts: "{{remotehost}}"
  gather_facts: false
  remote_user: opc
  connection: local

  collections:
    - kubernetes.core

  tasks:
    - name: Ensure the myapp Namespace exists.
      k8s:
        kubeconfig: /home/opc/.kube/config
        api_version: v1
        kind: Namespace
        name: myapp
        state: present

How do i ensure, that the script gets executed using the kubeconfig on the remote server, and not from. the ansible controller?

nafey1 avatar Dec 18 '22 05:12 nafey1

Hi @nafey1,

Could you please remove the connection: local from your playbook and give it another try? This is telling to Ansible that the host is a localhost. Also you need to review how your inventory file is built, it should be something like

all:
   hosts:
      server:
         ansible_host: 192.189.148.112

abikouo avatar Dec 20 '22 11:12 abikouo