Skip to content

Commit cdc4171

Browse files
committed
Add playbook to join a node and refactor playbs to use version variable (docker and k8s)
1 parent 09531da commit cdc4171

File tree

7 files changed

+69
-18
lines changed

7 files changed

+69
-18
lines changed

create-worker-node.yml

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
- name: create new worker node
2+
hosts: localhost
3+
connection: local
4+
gather_facts: false
5+
6+
vars_files:
7+
- "vm_vars/credentials.yaml"
8+
- "vm_vars/settings.yaml"
9+
vars:
10+
# redefine any VM variables that you want to override
11+
worker_name: node4
12+
ip: "{{ base_net }}.137" ## Important to set this up to a non taken ip within the vlan
13+
14+
tasks:
15+
16+
- name: worker creation
17+
gandi_vps:
18+
gandi_api_key: "{{ gandi_api_key }}"
19+
name: "{{ worker_name }}"
20+
image: "{{ image }}"
21+
machine_type: custom
22+
datacenter: "{{ datacenter }}"
23+
sshkey_ids:
24+
- "{{ gandi_ssh_key_id }}"
25+
cores: "{{ node_cpu }}"
26+
memory: "{{ node_mem }}"
27+
disk: "{{ node_disk }}"
28+
interfaces: {'privates': [{'vlan': "{{ vlan_name }}", 'ipv4': "{{ ip }}"}]}
29+
state: running
30+
farm: worker
31+
tags:
32+
- worker
33+
34+
- name: bootstrap kubernetes worker
35+
vars:
36+
#kube_token: # Generate a token
37+
#kubernetes_version: #if the version differs from the global one
38+
hosts: node4 #Rename to ${worker_name}
39+
roles:
40+
- common
41+
- docker
42+
- kube
43+
- worker
44+

group_vars/all.template

+2-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ kubeadm_reset: true
2626
ansible_user: root
2727

2828
# Versions
29-
node_exporter_version: 0.17.0
29+
kubernetes_version: "1.13.2-00"
30+
docker_version: "17.03.3~ce-0~ubuntu-xenial"
3031
alertmanager_version: 0.15.3
3132
docker_version: TBD #not used
3233

roles/common/tasks/main.yml

-5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
11
---
2-
3-
- include: node_exporter.yml
4-
52
- name: copy ssh keys
63
copy:
74
src: files/ssh_authorized_keys
@@ -22,5 +19,3 @@
2219
apt:
2320
update_cache: yes
2421
upgrade: dist
25-
26-

roles/docker/tasks/main.yml

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
- name: install dependencies
22
apt:
3-
package: {{ item }}
3+
package: "{{ item }}"
44
state: installed
55
update_cache: yes
66
with_items:
@@ -22,10 +22,10 @@
2222

2323
- name: install docker ce
2424
apt:
25-
package: {{ item }}
25+
package: "{{ item }}"
2626
update_cache: yes
2727
with_items:
28-
- docker-ce=17.03.3~ce-0~ubuntu-xenial
28+
- docker-ce={{ docker_version }}
2929

3030
- name: add user to group docker
3131
command: usermod -aG docker {{ ansible_user }}

roles/kube/tasks/main.yml

+8-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
- name: install dependencies
2-
apt: package={{ item }} state=installed update_cache=yes
2+
apt:
3+
package: "{{ item }}"
4+
state: installed
5+
update_cache: yes
36
with_items:
47
- apt-transport-https
58
- curl
@@ -16,6 +19,8 @@
1619
state: present
1720

1821
- name: install kube utilities
19-
apt: package={{ item }} update_cache=yes
22+
apt:
23+
package: "{{ item }}"
24+
update_cache: yes
2025
with_items:
21-
- kubectl
26+
- kubectl={{ kubernetes_version }}

roles/master/tasks/main.yml

+6-3
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,13 @@
22
command: swapoff -a
33

44
- name: install kube utilities
5-
apt: package={{ item }} update_cache=yes
5+
apt:
6+
package: "{{ item }}"
7+
update_cache: yes
68
with_items:
7-
- kubelet
8-
- kubeadm
9+
#- kubernetes-cni=0.6.0-00 # Temporary requirement if using kubernetes version 1.13.2
10+
- kubelet={{ kubernetes_version }}
11+
- kubeadm={{ kubernetes_version }}
912

1013
- name: reset kubeadm
1114
command: kubeadm reset --force

roles/worker/tasks/main.yml

+6-3
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,13 @@
22
command: swapoff -a
33

44
- name: install kube utilities
5-
apt: package={{ item }} update_cache=yes
5+
apt:
6+
package: "{{ item }}"
7+
update_cache: yes
68
with_items:
7-
- kubelet
8-
- kubeadm
9+
#- kubernetes-cni=0.6.0-00 # Temporary requirement if using kubernetes version 1.13.2
10+
- kubeadm={{ kubernetes_version }}
11+
- kubelet={{ kubernetes_version }}
912

1013
- name: reset before join
1114
command: kubeadm reset --force

0 commit comments

Comments
 (0)