From 012fa317bcb2f856a365231131ee228cb682e0dc Mon Sep 17 00:00:00 2001 From: Purname Yasa Date: Sat, 16 Nov 2024 05:23:31 +0800 Subject: [PATCH] Ansible RKE2: loop group servers on template configs --- .../RKE2/roles/add-server/templates/rke2-server-config.j2 | 6 +++--- .../RKE2/roles/rke2-prepare/templates/rke2-server-config.j2 | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) 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..f6b3b36 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 @@ -3,8 +3,8 @@ token: {{ hostvars['server1']['token'] }} server: https://{{ hostvars['server1']['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/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: