Skip to content

Commit acbf44a

Browse files
authored
Adds support for Ansible collections (#9582)
1 parent baed5f0 commit acbf44a

28 files changed

+1104
-899
lines changed

.gitignore

+4
Original file line numberDiff line numberDiff line change
@@ -114,3 +114,7 @@ roles/**/molecule/**/__pycache__/
114114
# Temp location used by our scripts
115115
scripts/tmp/
116116
tmp.md
117+
118+
# Ansible collection files
119+
kubernetes_sigs-kubespray*tar.gz
120+
ansible_collections

.gitlab-ci/lint.yml

+24
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,28 @@ syntax-check:
3939
ANSIBLE_VERBOSITY: "3"
4040
script:
4141
- ansible-playbook --syntax-check cluster.yml
42+
- ansible-playbook --syntax-check playbooks/cluster.yml
4243
- ansible-playbook --syntax-check upgrade-cluster.yml
44+
- ansible-playbook --syntax-check playbooks/upgrade-cluster.yml
4345
- ansible-playbook --syntax-check reset.yml
46+
- ansible-playbook --syntax-check playbooks/reset.yml
4447
- ansible-playbook --syntax-check extra_playbooks/upgrade-only-k8s.yml
4548
except: ['triggers', 'master']
4649

50+
collection-build-install-sanity-check:
51+
extends: .job
52+
stage: unit-tests
53+
tags: [light]
54+
variables:
55+
ANSIBLE_COLLECTIONS_PATH: "./ansible_collections"
56+
script:
57+
- ansible-galaxy collection build
58+
- ansible-galaxy collection install kubernetes_sigs-kubespray-$(grep "^version:" galaxy.yml | awk '{print $2}').tar.gz
59+
- ansible-galaxy collection list $(egrep -i '(name:\s+|namespace:\s+)' galaxy.yml | awk '{print $2}' | tr '\n' '.' | sed 's|\.$||g') | grep "^kubernetes_sigs.kubespray"
60+
- test -f ansible_collections/kubernetes_sigs/kubespray/playbooks/cluster.yml
61+
- test -f ansible_collections/kubernetes_sigs/kubespray/playbooks/reset.yml
62+
except: ['triggers', 'master']
63+
4764
tox-inventory-builder:
4865
stage: unit-tests
4966
tags: [light]
@@ -75,6 +92,13 @@ check-readme-versions:
7592
script:
7693
- tests/scripts/check_readme_versions.sh
7794

95+
check-galaxy-version:
96+
stage: unit-tests
97+
tags: [light]
98+
image: python:3
99+
script:
100+
- tests/scripts/check_galaxy_version.sh
101+
78102
check-typo:
79103
stage: unit-tests
80104
tags: [light]

.gitlab-ci/vagrant.yml

+5
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,11 @@ vagrant_ubuntu20-flannel:
4545
when: on_success
4646
allow_failure: false
4747

48+
vagrant_ubuntu20-flannel-collection:
49+
stage: deploy-part2
50+
extends: .vagrant
51+
when: on_success
52+
4853
vagrant_ubuntu16-kube-router-sep:
4954
stage: deploy-part2
5055
extends: .vagrant

README.md

+4
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,10 @@ docker run --rm -it --mount type=bind,source="$(pwd)"/inventory/sample,dst=/inve
7777
ansible-playbook -i /inventory/inventory.ini --private-key /root/.ssh/id_rsa cluster.yml
7878
```
7979

80+
#### Collection
81+
82+
See [here](docs/ansible_collection.md) if you wish to use this repository as an Ansible collection
83+
8084
### Vagrant
8185

8286
For Vagrant we need to install Python dependencies for provisioning tasks.

cluster.yml

+2-130
Original file line numberDiff line numberDiff line change
@@ -1,131 +1,3 @@
11
---
2-
- name: Check ansible version
3-
import_playbook: ansible_version.yml
4-
5-
- name: Ensure compatibility with old groups
6-
import_playbook: legacy_groups.yml
7-
8-
- hosts: bastion[0]
9-
gather_facts: False
10-
environment: "{{ proxy_disable_env }}"
11-
roles:
12-
- { role: kubespray-defaults }
13-
- { role: bastion-ssh-config, tags: ["localhost", "bastion"] }
14-
15-
- hosts: k8s_cluster:etcd
16-
strategy: linear
17-
any_errors_fatal: "{{ any_errors_fatal | default(true) }}"
18-
gather_facts: false
19-
environment: "{{ proxy_disable_env }}"
20-
roles:
21-
- { role: kubespray-defaults }
22-
- { role: bootstrap-os, tags: bootstrap-os}
23-
24-
- name: Gather facts
25-
tags: always
26-
import_playbook: facts.yml
27-
28-
- hosts: k8s_cluster:etcd
29-
gather_facts: False
30-
any_errors_fatal: "{{ any_errors_fatal | default(true) }}"
31-
environment: "{{ proxy_disable_env }}"
32-
roles:
33-
- { role: kubespray-defaults }
34-
- { role: kubernetes/preinstall, tags: preinstall }
35-
- { role: "container-engine", tags: "container-engine", when: deploy_container_engine }
36-
- { role: download, tags: download, when: "not skip_downloads" }
37-
38-
- hosts: etcd:kube_control_plane
39-
gather_facts: False
40-
any_errors_fatal: "{{ any_errors_fatal | default(true) }}"
41-
environment: "{{ proxy_disable_env }}"
42-
roles:
43-
- { role: kubespray-defaults }
44-
- role: etcd
45-
tags: etcd
46-
vars:
47-
etcd_cluster_setup: true
48-
etcd_events_cluster_setup: "{{ etcd_events_cluster_enabled }}"
49-
when: etcd_deployment_type != "kubeadm"
50-
51-
- hosts: k8s_cluster
52-
gather_facts: False
53-
any_errors_fatal: "{{ any_errors_fatal | default(true) }}"
54-
environment: "{{ proxy_disable_env }}"
55-
roles:
56-
- { role: kubespray-defaults }
57-
- role: etcd
58-
tags: etcd
59-
vars:
60-
etcd_cluster_setup: false
61-
etcd_events_cluster_setup: false
62-
when:
63-
- etcd_deployment_type != "kubeadm"
64-
- kube_network_plugin in ["calico", "flannel", "canal", "cilium"] or cilium_deploy_additionally | default(false) | bool
65-
- kube_network_plugin != "calico" or calico_datastore == "etcd"
66-
67-
- hosts: k8s_cluster
68-
gather_facts: False
69-
any_errors_fatal: "{{ any_errors_fatal | default(true) }}"
70-
environment: "{{ proxy_disable_env }}"
71-
roles:
72-
- { role: kubespray-defaults }
73-
- { role: kubernetes/node, tags: node }
74-
75-
- hosts: kube_control_plane
76-
gather_facts: False
77-
any_errors_fatal: "{{ any_errors_fatal | default(true) }}"
78-
environment: "{{ proxy_disable_env }}"
79-
roles:
80-
- { role: kubespray-defaults }
81-
- { role: kubernetes/control-plane, tags: master }
82-
- { role: kubernetes/client, tags: client }
83-
- { role: kubernetes-apps/cluster_roles, tags: cluster-roles }
84-
85-
- hosts: k8s_cluster
86-
gather_facts: False
87-
any_errors_fatal: "{{ any_errors_fatal | default(true) }}"
88-
environment: "{{ proxy_disable_env }}"
89-
roles:
90-
- { role: kubespray-defaults }
91-
- { role: kubernetes/kubeadm, tags: kubeadm}
92-
- { role: kubernetes/node-label, tags: node-label }
93-
- { role: network_plugin, tags: network }
94-
95-
- hosts: calico_rr
96-
gather_facts: False
97-
any_errors_fatal: "{{ any_errors_fatal | default(true) }}"
98-
environment: "{{ proxy_disable_env }}"
99-
roles:
100-
- { role: kubespray-defaults }
101-
- { role: network_plugin/calico/rr, tags: ['network', 'calico_rr'] }
102-
103-
- hosts: kube_control_plane[0]
104-
gather_facts: False
105-
any_errors_fatal: "{{ any_errors_fatal | default(true) }}"
106-
environment: "{{ proxy_disable_env }}"
107-
roles:
108-
- { role: kubespray-defaults }
109-
- { role: win_nodes/kubernetes_patch, tags: ["master", "win_nodes"] }
110-
111-
- hosts: kube_control_plane
112-
gather_facts: False
113-
any_errors_fatal: "{{ any_errors_fatal | default(true) }}"
114-
environment: "{{ proxy_disable_env }}"
115-
roles:
116-
- { role: kubespray-defaults }
117-
- { role: kubernetes-apps/external_cloud_controller, tags: external-cloud-controller }
118-
- { role: kubernetes-apps/network_plugin, tags: network }
119-
- { role: kubernetes-apps/policy_controller, tags: policy-controller }
120-
- { role: kubernetes-apps/ingress_controller, tags: ingress-controller }
121-
- { role: kubernetes-apps/external_provisioner, tags: external-provisioner }
122-
- { role: kubernetes-apps, tags: apps }
123-
124-
- name: Apply resolv.conf changes now that cluster DNS is up
125-
hosts: k8s_cluster
126-
gather_facts: False
127-
any_errors_fatal: "{{ any_errors_fatal | default(true) }}"
128-
environment: "{{ proxy_disable_env }}"
129-
roles:
130-
- { role: kubespray-defaults }
131-
- { role: kubernetes/preinstall, when: "dns_mode != 'none' and resolvconf_mode == 'host_resolvconf'", tags: resolvconf, dns_late: true }
2+
- name: Install Kubernetes
3+
ansible.builtin.import_playbook: playbooks/cluster.yml

docs/ansible_collection.md

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# Ansible collection
2+
3+
Kubespray can be installed as an [Ansible collection](https://docs.ansible.com/ansible/latest/user_guide/collections_using.html).
4+
5+
## Requirements
6+
7+
- An inventory file with the appropriate host groups. See the [README](../README.md#usage).
8+
- A `group_vars` directory. These group variables **need** to match the appropriate variable names under `inventory/local/group_vars`. See the [README](../README.md#usage).
9+
10+
## Usage
11+
12+
1. Add Kubespray to your requirements.yml file
13+
14+
```yaml
15+
collections:
16+
- name: https://github.com/kubernetes_sigs/kubespray
17+
type: git
18+
version: v2.21.0
19+
```
20+
21+
2. Install your collection
22+
23+
```ShellSession
24+
ansible-galaxy install -r requirements.yml
25+
```
26+
27+
3. Create a playbook to install your Kubernetes cluster
28+
29+
```yaml
30+
- name: Install Kubernetes
31+
ansible.builtin.import_playbook: kubernetes_sigs.kubespray.cluster
32+
```
33+
34+
4. Update INVENTORY and PLAYBOOK so that they point to your inventory file and the playbook you created above, and then install Kubespray
35+
36+
```ShellSession
37+
ansible-playbook -i INVENTORY --become --become-user=root PLAYBOOK
38+
```

galaxy.yml

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
---
2+
namespace: kubernetes_sigs
3+
description: Deploy a production ready Kubernetes cluster
4+
name: kubespray
5+
version: 2.21.0
6+
readme: README.md
7+
authors:
8+
- luksi1
9+
tags:
10+
- kubernetes
11+
- kubespray
12+
repository: https://github.com/kubernetes-sigs/kubespray
13+
build_ignore:
14+
- .github
15+
- '*.tar.gz'
16+
- extra_playbooks
17+
- inventory
18+
- scripts
19+
- test-infra
20+
- .ansible-lint
21+
- .editorconfig
22+
- .gitignore
23+
- .gitlab-ci
24+
- .gitlab-ci.yml
25+
- .gitmodules
26+
- .markdownlint.yaml
27+
- .nojekyll
28+
- .pre-commit-config.yaml
29+
- .yamllint
30+
- Dockerfile
31+
- FILES.json
32+
- MANIFEST.json
33+
- Makefile
34+
- Vagrantfile
35+
- _config.yml
36+
- ansible.cfg
37+
- requirements*txt
38+
- setup.cfg
39+
- setup.py
40+
- index.html
41+
- reset.yml
42+
- cluster.yml
43+
- scale.yml
44+
- recover-control-plane.yml
45+
- remove-node.yml
46+
- upgrade-cluster.yml
47+
- library

0 commit comments

Comments
 (0)