summaryrefslogtreecommitdiff
path: root/common/kubernetes-cluster-layout.yml
blob: 31751a8d714de986d1f6505f753d26837e53a676 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
---
- 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