diff --git a/defaults/main.yaml b/defaults/main.yaml index a008ca8..b56051d 100644 --- a/defaults/main.yaml +++ b/defaults/main.yaml @@ -38,7 +38,7 @@ rke2_server_service: rke2-server.service rke2_node_register_port: 9345 k8s_api_port: 6443 rke2_uninstall_script: /usr/local/bin/rke2-uninstall.sh -rke2_fetched_kubeconfig_path: ./kubeconfig +fetched_kubeconfig_path: ./kubeconfig rke2_path_to_generated_token: "{{ rke_dir }}/server/node-token" rke2_additional_manifests_path: "{{ rke_dir }}/server/manifests" rke2_release_kind: rke2r1 #rke2r2 @@ -164,7 +164,7 @@ k3s_config_dir: /etc/rancher/k3s k3s_config_name: k3s-config.yaml k3s_kubeconfig_path: /etc/rancher/k3s/k3s.yaml -helm_kubeconfig: "{{ k3s_kubeconfig_path if install_k3s|bool else rke2_kubeconfig_path }}" +path_to_kubeconfig: "{{ k3s_kubeconfig_path if install_k3s|bool else rke2_kubeconfig_path }}" k3s_config: flannel_backend: none disable_kube_proxy: true diff --git a/tasks/deploy-helm-charts.yaml b/tasks/deploy-helm-charts.yaml index 43fbf9f..af684e4 100644 --- a/tasks/deploy-helm-charts.yaml +++ b/tasks/deploy-helm-charts.yaml @@ -15,7 +15,7 @@ - name: Deploy helm charts kubernetes.core.helm: - kubeconfig: "{{ helm_kubeconfig }}" + kubeconfig: "{{ path_to_kubeconfig }}" name: "{{ item.key }}" chart_ref: "{{ item.value.ref }}" chart_version: "{{ item.value.version | default('latest') }}" @@ -30,7 +30,7 @@ - name: Deploy additional manifests kubernetes.core.k8s: - kubeconfig: "{{ helm_kubeconfig }}" + kubeconfig: "{{ path_to_kubeconfig }}" state: present definition: "{{ lookup('template', 'manifest-file.yaml.j2') | from_yaml }}" loop: "{{ q('ansible.builtin.dict', additional_helm_manifests) }}" diff --git a/tasks/deploy-k3s.yaml b/tasks/deploy-k3s.yaml index 4d0a14a..0d330c3 100644 --- a/tasks/deploy-k3s.yaml +++ b/tasks/deploy-k3s.yaml @@ -34,6 +34,13 @@ run_once: true delegate_to: initial_master_node +- name: Add external ip to kubeconfig + ansible.builtin.lineinfile: + path: "{{ k3s_kubeconfig_path }}" + regexp: "127.0.0.1:{{ k8s_api_port }}" + line: " server: https://{% for host in groups['initial_master_node'] %}{{ hostvars[host]['ansible_default_ipv4']['address'] }}{% endfor %}:{{ k8s_api_port }}" + delegate_to: initial_master_node + - name: Deploy additional nodes ansible.builtin.shell: | curl -sfL {{ k3s_installscript_url }} | sh -s - diff --git a/tasks/main.yaml b/tasks/main.yaml index a6f37ad..589feee 100644 --- a/tasks/main.yaml +++ b/tasks/main.yaml @@ -45,8 +45,8 @@ - name: Fetch kubeconfig local to ansible host ansible.builtin.fetch: - src: "{{ rke2_kubeconfig_path }}" - dest: "{{ rke2_fetched_kubeconfig_path }}" + src: "{{ path_to_kubeconfig }}" + dest: "{{ fetched_kubeconfig_path }}" flat: yes run_once: true when: inventory_hostname in groups['initial_master_node'] and fetch_kubeconfig|bool