Skip to content

Commit

Permalink
Factorize some identical playbooks steps into their own sub-playbooks (
Browse files Browse the repository at this point in the history
…kubernetes-sigs#10633)

* Factorize identical playboooks steps in sub-playbooks

* Copy legacy_groups.yml into its sole user
  • Loading branch information
VannTen authored and pedromcpedro committed May 8, 2024
1 parent b43ff11 commit 329c514
Show file tree
Hide file tree
Showing 8 changed files with 57 additions and 137 deletions.
13 changes: 12 additions & 1 deletion playbooks/legacy_groups.yml → playbooks/boilerplate.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
---
# This is an inventory compatibility playbook to ensure we keep compatibility with old style group names
- name: Check ansible version
import_playbook: ansible_version.yml

# These are inventory compatibility tasks to ensure we keep compatibility with old style group names

- name: Add kube-master nodes to kube_control_plane
hosts: kube-master
Expand Down Expand Up @@ -45,3 +48,11 @@
- name: Add nodes to no-floating group
group_by:
key: 'no_floating'

- name: Install bastion ssh config
hosts: bastion[0]
gather_facts: False
environment: "{{ proxy_disable_env }}"
roles:
- { role: kubespray-defaults }
- { role: bastion-ssh-config, tags: ["localhost", "bastion"] }
45 changes: 3 additions & 42 deletions playbooks/cluster.yml
Original file line number Diff line number Diff line change
@@ -1,17 +1,6 @@
---
- name: Check ansible version
import_playbook: ansible_version.yml

- name: Ensure compatibility with old groups
import_playbook: legacy_groups.yml

- name: Install bastion ssh config
hosts: bastion[0]
gather_facts: False
environment: "{{ proxy_disable_env }}"
roles:
- { role: kubespray-defaults }
- { role: bastion-ssh-config, tags: ["localhost", "bastion"] }
- name: Common tasks for every playbooks
import_playbook: boilerplate.yml

- name: Gather facts
import_playbook: facts.yml
Expand All @@ -28,35 +17,7 @@
- { role: download, tags: download, when: "not skip_downloads" }

- name: Install etcd
hosts: etcd:kube_control_plane
gather_facts: False
any_errors_fatal: "{{ any_errors_fatal | default(true) }}"
environment: "{{ proxy_disable_env }}"
roles:
- { role: kubespray-defaults }
- role: etcd
tags: etcd
vars:
etcd_cluster_setup: true
etcd_events_cluster_setup: "{{ etcd_events_cluster_enabled }}"
when: etcd_deployment_type != "kubeadm"

- name: Install etcd certs on nodes if required
hosts: k8s_cluster
gather_facts: False
any_errors_fatal: "{{ any_errors_fatal | default(true) }}"
environment: "{{ proxy_disable_env }}"
roles:
- { role: kubespray-defaults }
- role: etcd
tags: etcd
vars:
etcd_cluster_setup: false
etcd_events_cluster_setup: false
when:
- etcd_deployment_type != "kubeadm"
- kube_network_plugin in ["calico", "flannel", "canal", "cilium"] or cilium_deploy_additionally | default(false) | bool
- kube_network_plugin != "calico" or calico_datastore == "etcd"
import_playbook: install_etcd.yml

- name: Install Kubernetes nodes
hosts: k8s_cluster
Expand Down
31 changes: 31 additions & 0 deletions playbooks/install_etcd.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
---
- name: Install etcd
hosts: etcd:kube_control_plane
gather_facts: False
any_errors_fatal: "{{ any_errors_fatal | default(true) }}"
environment: "{{ proxy_disable_env }}"
roles:
- { role: kubespray-defaults }
- role: etcd
tags: etcd
vars:
etcd_cluster_setup: true
etcd_events_cluster_setup: "{{ etcd_events_cluster_enabled }}"
when: etcd_deployment_type != "kubeadm"

- name: Install etcd certs on nodes if required
hosts: k8s_cluster
gather_facts: False
any_errors_fatal: "{{ any_errors_fatal | default(true) }}"
environment: "{{ proxy_disable_env }}"
roles:
- { role: kubespray-defaults }
- role: etcd
tags: etcd
vars:
etcd_cluster_setup: false
etcd_events_cluster_setup: false
when:
- etcd_deployment_type != "kubeadm"
- kube_network_plugin in ["calico", "flannel", "canal", "cilium"] or cilium_deploy_additionally | default(false) | bool
- kube_network_plugin != "calico" or calico_datastore == "etcd"
15 changes: 2 additions & 13 deletions playbooks/recover_control_plane.yml
Original file line number Diff line number Diff line change
@@ -1,17 +1,6 @@
---
- name: Check ansible version
import_playbook: ansible_version.yml

- name: Ensure compatibility with old groups
import_playbook: legacy_groups.yml

- name: Install bastion ssh config
hosts: bastion[0]
gather_facts: False
environment: "{{ proxy_disable_env }}"
roles:
- { role: kubespray-defaults}
- { role: bastion-ssh-config, tags: ["localhost", "bastion"]}
- name: Common tasks for every playbooks
import_playbook: boilerplate.yml

- name: Recover etcd
hosts: etcd[0]
Expand Down
15 changes: 2 additions & 13 deletions playbooks/remove_node.yml
Original file line number Diff line number Diff line change
@@ -1,17 +1,6 @@
---
- name: Check ansible version
import_playbook: ansible_version.yml

- name: Ensure compatibility with old groups
import_playbook: legacy_groups.yml

- name: Install bastion ssh config
hosts: bastion[0]
gather_facts: False
environment: "{{ proxy_disable_env }}"
roles:
- { role: kubespray-defaults }
- { role: bastion-ssh-config, tags: ["localhost", "bastion"] }
- name: Common tasks for every playbooks
import_playbook: boilerplate.yml

- name: Confirm node removal
hosts: "{{ node | default('etcd:k8s_cluster:calico_rr') }}"
Expand Down
15 changes: 2 additions & 13 deletions playbooks/reset.yml
Original file line number Diff line number Diff line change
@@ -1,17 +1,6 @@
---
- name: Check ansible version
import_playbook: ansible_version.yml

- name: Ensure compatibility with old groups
import_playbook: legacy_groups.yml

- name: Install bastion ssh config
hosts: bastion[0]
gather_facts: False
environment: "{{ proxy_disable_env }}"
roles:
- { role: kubespray-defaults}
- { role: bastion-ssh-config, tags: ["localhost", "bastion"]}
- name: Common tasks for every playbooks
import_playbook: boilerplate.yml

- name: Gather facts
import_playbook: facts.yml
Expand Down
15 changes: 2 additions & 13 deletions playbooks/scale.yml
Original file line number Diff line number Diff line change
@@ -1,17 +1,6 @@
---
- name: Check ansible version
import_playbook: ansible_version.yml

- name: Ensure compatibility with old groups
import_playbook: legacy_groups.yml

- name: Install bastion ssh config
hosts: bastion[0]
gather_facts: False
environment: "{{ proxy_disable_env }}"
roles:
- { role: kubespray-defaults }
- { role: bastion-ssh-config, tags: ["localhost", "bastion"] }
- name: Common tasks for every playbooks
import_playbook: boilerplate.yml

- name: Gather facts
import_playbook: facts.yml
Expand Down
45 changes: 3 additions & 42 deletions playbooks/upgrade_cluster.yml
Original file line number Diff line number Diff line change
@@ -1,17 +1,6 @@
---
- name: Check ansible version
import_playbook: ansible_version.yml

- name: Ensure compatibility with old groups
import_playbook: legacy_groups.yml

- name: Install bastion ssh config
hosts: bastion[0]
gather_facts: False
environment: "{{ proxy_disable_env }}"
roles:
- { role: kubespray-defaults }
- { role: bastion-ssh-config, tags: ["localhost", "bastion"] }
- name: Common tasks for every playbooks
import_playbook: boilerplate.yml

- name: Gather facts
import_playbook: facts.yml
Expand Down Expand Up @@ -47,35 +36,7 @@
- { role: container-engine, tags: "container-engine", when: deploy_container_engine }

- name: Install etcd
hosts: etcd:kube_control_plane
gather_facts: False
any_errors_fatal: "{{ any_errors_fatal | default(true) }}"
environment: "{{ proxy_disable_env }}"
roles:
- { role: kubespray-defaults }
- role: etcd
tags: etcd
vars:
etcd_cluster_setup: true
etcd_events_cluster_setup: "{{ etcd_events_cluster_enabled }}"
when: etcd_deployment_type != "kubeadm"

- name: Install etcd certs on nodes if required
hosts: k8s_cluster
gather_facts: False
any_errors_fatal: "{{ any_errors_fatal | default(true) }}"
environment: "{{ proxy_disable_env }}"
roles:
- { role: kubespray-defaults }
- role: etcd
tags: etcd
vars:
etcd_cluster_setup: false
etcd_events_cluster_setup: false
when:
- etcd_deployment_type != "kubeadm"
- kube_network_plugin in ["calico", "flannel", "canal", "cilium"] or cilium_deploy_additionally | default(false) | bool
- kube_network_plugin != "calico" or calico_datastore == "etcd"
import_playbook: install_etcd.yml

- name: Handle upgrades to master components first to maintain backwards compat.
gather_facts: False
Expand Down

0 comments on commit 329c514

Please sign in to comment.