--- - name: create host groups for kubernetes cluster hosts: "{{ kubernetes_cluster_layout.nodes_group }}" connection: local gather_facts: no run_once: yes tasks: - name: sanity check - fail if control-plane nodes are not included in node group assert: msg: "the cluster node group '{{ kubernetes_cluster_layout.nodes_group }}' must include *all* nodes (control-plane and worker)" that: kubernetes_cluster_layout.controlplane_nodes | difference(ansible_play_hosts_all) | length == 0 - name: sanity check - fail if primary control-group node is not in control-group node list assert: msg: "kubernetes_cluster_layout.controlplane_nodes must include kubernetes_cluster_layout.primary_controlplane_node" that: kubernetes_cluster_layout.primary_controlplane_node is undefined or kubernetes_cluster_layout.primary_controlplane_node in kubernetes_cluster_layout.controlplane_nodes - name: sanity check - fail on multiple control-plane nodes but no primary is configured assert: msg: "for multiple control-plane nodes to work you need to define kubernetes_cluster_layout.primary_controlplane_node" that: (kubernetes_cluster_layout.controlplane_nodes | length) == 1 or kubernetes_cluster_layout.primary_controlplane_node is defined - name: create group for all kubernetes nodes loop: "{{ ansible_play_hosts_all }}" add_host: name: "{{ item }}" inventory_dir: "{{ hostvars[item].inventory_dir }}" group: _kubernetes_nodes_ changed_when: False - name: create group for kubernetes control-plane nodes loop: "{{ kubernetes_cluster_layout.controlplane_nodes }}" add_host: name: "{{ item }}" inventory_dir: "{{ hostvars[item].inventory_dir }}" group: _kubernetes_controlplane_nodes_ changed_when: False - name: create group for kubernetes primary control-plane node vars: item: "{{ kubernetes_cluster_layout.primary_controlplane_node | default(kubernetes_cluster_layout.controlplane_nodes[0]) }}" add_host: name: "{{ item }}" inventory_dir: "{{ hostvars[item].inventory_dir }}" group: _kubernetes_primary_controlplane_node_ changed_when: False