Home > other >  why does ansible not see admin.conf and it needs to be manually exported?
why does ansible not see admin.conf and it needs to be manually exported?

Time:09-10

why does ansible not see admin.conf when creating resources in the cloud?

- name: apply ingress
  shell: export KUBECONFIG=/etc/kubernetes/admin.conf && kubectl apply -f /home/ingress.yaml

works like this and sees everything, and if so

- name: apply ingress
  shell: kubectl apply -f /home/ingress.yaml

error:

The connection to the server localhost:8080 was refused - did you specify the right host or port?", "stderr_lines": ["The connection to the server localhost:8080 was refused - did you specify the right host or port?"], "stdout": "", "stdout_lines": []}

at the same time, if I log on to the server via ssh, the command is used under the ubuntu order, and under the root order, without exports.

P.S. just in case, I copied admin.conf to the user directory

- name: Create directory for kube config.
  become: yes
  file:
    path: /home/{{  ansible_user }}/.kube
    state: directory
    owner: "{{ ansible_user }}"
    group: "{{ ansible_user }}"
    mode: 0755
- name: Copy admin.conf to user's home directory
  become_user: root
  become_method: sudo
  become: true
  copy:
    src: /etc/kubernetes/admin.conf
    dest: "/home/{{ ansible_user }}/.kube/config"
    remote_src: yes
    owner: "{{ ansible_user }}"
    group: "{{ ansible_user }}"
    mode: 0644

CodePudding user response:

i dont know why, but solution:

  • name: apply ingress become: true become: ubuntu shell: kubectl apply -f /home/ingress.yaml
  • Related