Move download of kube-config into dedicated role

This commit is contained in:
2025-09-19 14:13:15 +02:00
parent d227c954a6
commit 95cc115734
3 changed files with 26 additions and 19 deletions

View File

@@ -1,15 +0,0 @@
- hosts: server[0]
tasks:
- name: Download kube-config
fetch:
src: /etc/rancher/k3s/k3s.yaml
dest: "{{ lookup('env', 'HOME') }}/.kube/config"
flat: true
- hosts: localhost
tasks:
- name: Use correct ip-address for k8s-cluster
lineinfile:
path: "{{ lookup('env', 'HOME') }}/.kube/config"
regexp: '^(\s*server: https://).*(:\d+)$'
line: \g<1>{{ hostvars[groups['server'][0]]['api_endpoint'] }}\g<2>
backrefs: yes

View File

@@ -0,0 +1,19 @@
- name: Download kube-config
fetch:
src: /etc/rancher/k3s/k3s.yaml
dest: "{{ lookup('env', 'HOME') }}/.kube/config.orig"
flat: true
register: loaded_kube_config
- name: Copy kube-config to correct location
delegate_to: localhost
copy:
src: "{{ lookup('env', 'HOME') }}/.kube/config.orig"
dest: "{{ lookup('env', 'HOME') }}/.kube/config"
when: hostvars[groups['server'][0]]['loaded_kube_config'] is changed
- name: Use correct ip-address for k8s-cluster
delegate_to: localhost
lineinfile:
path: "{{ lookup('env', 'HOME') }}/.kube/config"
regexp: '^(\s*server: https://).*(:\d+)$'
line: \g<1>{{ hostvars[groups['server'][0]]['api_endpoint'] }}\g<2>
backrefs: yes

View File

@@ -16,10 +16,13 @@
- init
- add-server
- add-agent
- import_playbook: download-kube-config.yml
tags:
- init
- config
- import_playbook: k3s.orchestration.upgrade
tags:
- update
- hosts: server[0]
roles:
- role: kube-config
tags:
- init
- config
- update