Test group membership with group_names

Testing for group membership with group names makes Kubespray more
tolerant towards the structure of the inventory.
Where 'inventory_hostname in groups["some_group"] would fail if
"some_group" is not defined, '"some_group" in group_names' would not.
This commit is contained in:
Max Gautier
2024-09-21 14:09:09 +02:00
parent 89ff0710e9
commit 2ec1c93897
22 changed files with 60 additions and 60 deletions

View File

@@ -121,7 +121,7 @@
- name: Calico | kdd specific configuration
when:
- inventory_hostname in groups['kube_control_plane']
- ('kube_control_plane' in group_names)
- calico_datastore == "kdd"
block:
- name: Calico | Check if extra directory is needed
@@ -321,7 +321,7 @@
nodeToNodeMeshEnabled: "false"
when:
- peer_with_router | default(false) or peer_with_calico_rr | default(false)
- inventory_hostname in groups['k8s_cluster']
- ('k8s_cluster' in group_names)
run_once: true
- name: Calico | Configure Calico BGP
@@ -382,7 +382,7 @@
- {name: kubernetes-services-endpoint, file: kubernetes-services-endpoint.yml, type: cm }
register: calico_node_manifests
when:
- inventory_hostname in groups['kube_control_plane']
- ('kube_control_plane' in group_names)
- rbac_enabled or item.type not in rbac_resources
- name: Calico | Create calico manifests for typha
@@ -394,7 +394,7 @@
- {name: calico, file: calico-typha.yml, type: typha}
register: calico_node_typha_manifest
when:
- inventory_hostname in groups['kube_control_plane']
- ('kube_control_plane' in group_names)
- typha_enabled
- name: Calico | get calico apiserver caBundle
@@ -421,7 +421,7 @@
- {name: calico, file: calico-apiserver.yml, type: calico-apiserver}
register: calico_apiserver_manifest
when:
- inventory_hostname in groups['kube_control_plane']
- ('kube_control_plane' in group_names)
- calico_apiserver_enabled
- name: Start Calico resources
@@ -473,7 +473,7 @@
with_items:
- {name: calico, file: calico-ipamconfig.yml, type: ipam}
when:
- inventory_hostname in groups['kube_control_plane']
- ('kube_control_plane' in group_names)
- calico_datastore == "kdd"
- name: Calico | Create ipamconfig resources

View File

@@ -32,7 +32,7 @@
when:
- calico_rr_id is defined
- calico_group_id is defined
- inventory_hostname in groups['calico_rr']
- ('calico_rr' in group_names)
- name: Calico | Configure peering with route reflectors at global scope
command:

View File

@@ -28,7 +28,7 @@
cmd: "{{ bin_dir }}/calicoctl.sh get node {{ inventory_hostname }}"
register: output_get_node
when:
- inventory_hostname in groups['k8s_cluster']
- ('k8s_cluster' in group_names)
- local_as is defined
- groups['calico_rr'] | default([]) | length == 0
delegate_to: "{{ groups['kube_control_plane'][0] }}"
@@ -50,7 +50,7 @@
until: output.rc == 0
delay: "{{ retry_stagger | random + 3 }}"
when:
- inventory_hostname in groups['k8s_cluster']
- ('k8s_cluster' in group_names)
- local_as is defined
- groups['calico_rr'] | default([]) | length == 0
- output_get_node.rc == 0
@@ -77,7 +77,7 @@
until: output.rc == 0
delay: "{{ retry_stagger | random + 3 }}"
when:
- inventory_hostname in groups['k8s_cluster']
- ('k8s_cluster' in group_names)
- local_as is defined
- groups['calico_rr'] | default([]) | length == 0
- output_get_node.rc != 0
@@ -110,4 +110,4 @@
- "{{ peers | default([]) | selectattr('scope', 'undefined') | list | union(peers | default([]) | selectattr('scope', 'defined') | selectattr('scope', 'equalto', 'node') | list ) }}"
delegate_to: "{{ groups['kube_control_plane'][0] }}"
when:
- inventory_hostname in groups['k8s_cluster']
- ('k8s_cluster' in group_names)

View File

@@ -59,7 +59,7 @@
- {name: cilium, file: sa.yml, type: sa}
register: cilium_node_manifests
when:
- inventory_hostname in groups['kube_control_plane']
- ('kube_control_plane' in group_names)
- item.when | default(True) | bool
- name: Cilium | Create Cilium Hubble manifests

View File

@@ -4,18 +4,18 @@
with_items:
- "{{ kube_router_annotations_master }}"
delegate_to: "{{ groups['kube_control_plane'][0] }}"
when: kube_router_annotations_master is defined and inventory_hostname in groups['kube_control_plane']
when: kube_router_annotations_master is defined and 'kube_control_plane' in group_names
- name: Kube-router | Add annotations on kube_node
command: "{{ kubectl }} annotate --overwrite node {{ ansible_hostname }} {{ item }}"
with_items:
- "{{ kube_router_annotations_node }}"
delegate_to: "{{ groups['kube_control_plane'][0] }}"
when: kube_router_annotations_node is defined and inventory_hostname in groups['kube_node']
when: kube_router_annotations_node is defined and 'kube_node' in group_names
- name: Kube-router | Add common annotations on all servers
command: "{{ kubectl }} annotate --overwrite node {{ ansible_hostname }} {{ item }}"
with_items:
- "{{ kube_router_annotations_all }}"
delegate_to: "{{ groups['kube_control_plane'][0] }}"
when: kube_router_annotations_all is defined and inventory_hostname in groups['k8s_cluster']
when: kube_router_annotations_all is defined and 'k8s_cluster' in group_names