From 7580e59bbfb31bffa748f71ffcaaf5b459b8aebc Mon Sep 17 00:00:00 2001 From: Max Gautier Date: Sat, 21 Sep 2024 14:16:17 +0200 Subject: [PATCH] Define k8s_cluster dynamically This allows inventories to not define the k8s_cluster group manually. --- playbooks/boilerplate.yml | 20 ++++++++++--------- .../roles/packet-ci/templates/inventory.j2 | 7 ------- 2 files changed, 11 insertions(+), 16 deletions(-) diff --git a/playbooks/boilerplate.yml b/playbooks/boilerplate.yml index eafa9b42f12..66d50d63462 100644 --- a/playbooks/boilerplate.yml +++ b/playbooks/boilerplate.yml @@ -2,7 +2,9 @@ - name: Check ansible version import_playbook: ansible_version.yml -# These are inventory compatibility tasks to ensure we keep compatibility with old style group names +# These are inventory compatibility tasks with two purposes: +# - to ensure we keep compatibility with old style group names +# - to reduce inventory boilerplate (defining parent groups / empty groups) - name: Add kube-master nodes to kube_control_plane hosts: kube-master @@ -22,23 +24,23 @@ group_by: key: 'kube_node' -- name: Add k8s-cluster nodes to k8s_cluster - hosts: k8s-cluster +- name: Add calico-rr nodes to calico_rr + hosts: calico-rr gather_facts: false tags: always tasks: - - name: Add nodes to k8s_cluster group + - name: Add nodes to calico_rr group group_by: - key: 'k8s_cluster' + key: 'calico_rr' -- name: Add calico-rr nodes to calico_rr - hosts: calico-rr +- name: Define k8s_cluster group + hosts: kube_node:kube_control_plane:calico_rr gather_facts: false tags: always tasks: - - name: Add nodes to calico_rr group + - name: Add nodes to k8s_cluster group group_by: - key: 'calico_rr' + key: 'k8s_cluster' - name: Add no-floating nodes to no_floating hosts: no-floating diff --git a/tests/cloud_playbooks/roles/packet-ci/templates/inventory.j2 b/tests/cloud_playbooks/roles/packet-ci/templates/inventory.j2 index e7adafccce9..1801a740a3b 100644 --- a/tests/cloud_playbooks/roles/packet-ci/templates/inventory.j2 +++ b/tests/cloud_playbooks/roles/packet-ci/templates/inventory.j2 @@ -96,10 +96,3 @@ instance-2 instance-3 instance-4 {% endif %} - -[k8s_cluster:children] -kube_node -kube_control_plane -calico_rr - -[calico_rr]