Move download of kube-config into dedicated role
This commit is contained in:
@@ -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
|
||||
19
k3s/roles/kube-config/tasks/main.yml
Normal file
19
k3s/roles/kube-config/tasks/main.yml
Normal 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
|
||||
11
k3s/site.yml
11
k3s/site.yml
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user