Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions fetch.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
---
# Playbook used to download a copy of the kubeconfig file from a RKE cluster.
- name: Ensure outputs directory exists
hosts: localhost
vars:
output_directory: outputs
tasks:
- name: Create outputs directory
file:
path: "{{ output_directory }}"
state: directory

- name: Patch and download the kubeconfig
hosts: controllers[0]
vars:
temp_file: /tmp/kubeconfig
tasks:
- name: Copy kubeconfig file for patching and download
copy:
src: /etc/rancher/rke2/rke2.yaml
dest: "{{ temp_file }}"
mode: 0600
remote_src: yes

- name: Patch the server address in the original kubeconfig
lineinfile:
path: "{{ temp_file }}"
regexp: 'server: https://127\.0\.0\.1:6443'
line: " server: https://{{ ansible_ssh_host }}:6443"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can cluster_hostname be used for this instead of ansible_ssh_host? If I recall correctly, cluster_hostname defaults to ansible_ssh_host if it's not specified.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can test it, but I want the kubeconfig to be valid for the public IP address not just the hostname.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, in which case you can specify the ip for cluster_hostname, which is what happens by default.


- name: Download the kubeconfig
fetch:
src: "{{ temp_file }}"
dest: "{{ hostvars['localhost']['output_directory']}}/{{ ansible_hostname }}.kube.config"
flat: yes

- name: Cleanup the temp file
file:
path: "{{ temp_file }}"
state: absent
1 change: 1 addition & 0 deletions roles/rke/templates/rke2_config.j2
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ write-kubeconfig-mode: "0600"
disable: rke2-ingress-nginx
tls-san:
- {{ cluster_hostname }}
- {{ ansible_ssh_host }}
{% endif %}

{% if not is_rke_registration_server %}
Expand Down