diff --git a/Ansible/Playbooks/RKE2/roles/add-agent/templates/rke2-agent-config.j2 b/Ansible/Playbooks/RKE2/roles/add-agent/templates/rke2-agent-config.j2 index 3dafb3d..c8634f6 100644 --- a/Ansible/Playbooks/RKE2/roles/add-agent/templates/rke2-agent-config.j2 +++ b/Ansible/Playbooks/RKE2/roles/add-agent/templates/rke2-agent-config.j2 @@ -1,5 +1,5 @@ write-kubeconfig-mode: "0644" -token: {{ hostvars['server1']['token'] }} -server: https://{{ hostvars['server1']['ansible_host'] }}:9345 +token: {{ hostvars[groups['servers'][0]]['token'] }} +server: https://{{ hostvars[groups['servers'][0]]['ansible_host'] }}:9345 node-label: - "agent=true" diff --git a/Ansible/Playbooks/RKE2/roles/add-server/templates/rke2-server-config.j2 b/Ansible/Playbooks/RKE2/roles/add-server/templates/rke2-server-config.j2 index d7a51e8..24b2b49 100644 --- a/Ansible/Playbooks/RKE2/roles/add-server/templates/rke2-server-config.j2 +++ b/Ansible/Playbooks/RKE2/roles/add-server/templates/rke2-server-config.j2 @@ -1,10 +1,10 @@ write-kubeconfig-mode: "0644" -token: {{ hostvars['server1']['token'] }} -server: https://{{ hostvars['server1']['ansible_host'] }}:9345 +token: {{ hostvars[groups['servers'][0]]['token'] }} +server: https://{{ hostvars[groups['servers'][0]]['ansible_host'] }}:9345 tls-san: - {{ vip }} - - {{ hostvars['server1']['ansible_host'] }} - - {{ hostvars['server2']['ansible_host'] }} - - {{ hostvars['server3']['ansible_host'] }} +{% for host in groups['servers'] %} + - {{ hostvars[host]['ansible_host'] }} +{% endfor %} node-label: - server=true \ No newline at end of file diff --git a/Ansible/Playbooks/RKE2/roles/rke2-prepare/tasks/main.yaml b/Ansible/Playbooks/RKE2/roles/rke2-prepare/tasks/main.yaml index f1fbccc..cf0c6a2 100644 --- a/Ansible/Playbooks/RKE2/roles/rke2-prepare/tasks/main.yaml +++ b/Ansible/Playbooks/RKE2/roles/rke2-prepare/tasks/main.yaml @@ -47,7 +47,7 @@ daemon_reload: true when: inventory_hostname in groups['servers'][0] -# wait for node token to be availale so that we can copy it, we need this to join other nodes +# wait for node token to be available so that we can copy it, we need this to join other nodes - name: Wait for node-token ansible.builtin.wait_for: path: /var/lib/rancher/rke2/server/node-token @@ -126,9 +126,9 @@ when: inventory_hostname == groups['servers'][0] # change IP from local to server 1 IP -- name: Replace IP address with server1 +- name: Replace IP address with first server ansible.builtin.replace: path: /home/{{ ansible_user }}/.kube/config regexp: '127.0.0.1' - replace: "{{ hostvars['server1']['ansible_host'] }}" + replace: "{{ hostvars[groups['servers'][0]]['ansible_host'] }}" when: inventory_hostname == groups['servers'][0] diff --git a/Ansible/Playbooks/RKE2/roles/rke2-prepare/templates/rke2-server-config.j2 b/Ansible/Playbooks/RKE2/roles/rke2-prepare/templates/rke2-server-config.j2 index a3131f1..d01a93e 100644 --- a/Ansible/Playbooks/RKE2/roles/rke2-prepare/templates/rke2-server-config.j2 +++ b/Ansible/Playbooks/RKE2/roles/rke2-prepare/templates/rke2-server-config.j2 @@ -1,9 +1,9 @@ write-kubeconfig-mode: "0644" tls-san: - {{ vip }} - - {{ hostvars['server1']['ansible_host'] }} - - {{ hostvars['server2']['ansible_host'] }} - - {{ hostvars['server3']['ansible_host'] }} +{% for host in groups['servers'] %} + - {{ hostvars[host]['ansible_host'] }} +{% endfor %} node-label: - server=true disable: