summaryrefslogtreecommitdiff
path: root/common/kubernetes-cluster-layout.yml
blob: bd972a6df55e0275b6da76753ee060936b28a936 (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 masters are not included in nodes
    assert:
      msg: "the cluster node group '{{ kubernetes_cluster_layout.nodes_group }}' must include *all* nodes (master and non-master)"
      that: kubernetes_cluster_layout.masters | difference(ansible_play_hosts_all) | length == 0

  - name: sanity check - fail if primary master is not in masters
    assert:
      msg: "kubernetes_cluster_layout.masters must include kubernetes_cluster_layout.primary_master"
      that: kubernetes_cluster_layout.primary_master is undefined or kubernetes_cluster_layout.primary_master in kubernetes_cluster_layout.masters

  - name: sanity check - fail on multiple masters if no primary master is configured
    assert:
      msg: "for multiple masters to work you need to define kubernetes_cluster_layout.primary_master"
      that: (kubernetes_cluster_layout.masters | length) == 1 or kubernetes_cluster_layout.primary_master 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 master nodes
    loop: "{{ kubernetes_cluster_layout.masters }}"
    add_host:
      name: "{{ item }}"
      inventory_dir: "{{ hostvars[item].inventory_dir }}"
      group: _kubernetes_masters_
    changed_when: False

  - name: create group for kubernetes primary master
    vars:
      item: "{{ kubernetes_cluster_layout.primary_master | default(kubernetes_cluster_layout.masters[0]) }}"
    add_host:
      name: "{{ item }}"
      inventory_dir: "{{ hostvars[item].inventory_dir }}"
      group: _kubernetes_primary_master_
    changed_when: False