-
Notifications
You must be signed in to change notification settings - Fork 34
/
playbook-1804.yaml
153 lines (148 loc) · 5.19 KB
/
playbook-1804.yaml
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
---
- hosts: all
become: true
tasks:
- name: install apt-transport-https
apt: name=apt-transport-https state=latest update_cache=yes
- name: apt get update cache
apt: update_cache=yes
- name: apt upgrade
apt: name='*' state=latest
- name: apt docker io
apt: name=docker.io state=latest update_cache=yes
- name: stop docker io
systemd: name=docker state=stopped
- name: install daemon.json
template:
src: daemon.j2
dest: /etc/docker/daemon.json
- name: reload the docker daemon
systemd:
name: docker
state: started
- name: enable service docker
systemd:
name: docker
enabled: yes
masked: no
- name: set kubernetes deb repo in apt source list
lineinfile: create=yes
dest=/etc/apt/sources.list.d/kubernetes.list
line="deb http://apt.kubernetes.io/ kubernetes-xenial main"
- name: get depo key
shell: curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | apt-key add -
- name: Remove swapfile from /etc/fstab
mount:
name: "{{ item}}"
fstype: swap
state: absent
with_items:
- swap
- none
- name: Disable Swap
shell: |
swapoff -a
when: ansible_swaptotal_mb > 0
- name: Install kubadm
apt:
name: kubeadm
state: present
update_cache: yes
- name: install kubelet
apt:
name: kubelet
state: present
update_cache: yes
- name: install kubectl
apt:
name: kubectl
state: present
update_cache: yes
- name: create .kube directory
file:
path: /home/{{ansible_ssh_user}}/.kube
state: directory
owner: "{{ansible_ssh_user}}"
group: "{{ansible_ssh_user}}"
- hosts: master
become: true
tasks:
- name: get rbac
become_user: "{{ ansible_ssh_user }}"
get_url:
url: https://tinyurl.com/yb4xturm
dest: /home/{{ ansible_ssh_user }}
#- name: get calico
# become_user: ubuntu
# get_url:
# url: https://tinyurl.com/y8lvqc9g
# dest: /home/{{ansible_ssh_user}}
- name: run kubeadm init
shell: kubeadm init --pod-network-cidr 192.168.0.0/16 | tee kubeadm-init.out
- name: copy master admin.conf to ansible controller
get_url:
url: file:///etc/kubernetes/admin.conf
dest: /home/{{ansible_ssh_user}}/.kube/config
owner: "{{ ansible_ssh_user }}"
group: "{{ ansible_ssh_user }}"
- name: Fetch the file from master to the ansible controller
run_once: yes
fetch: src=/etc/kubernetes/admin.conf dest=/tmp/admin.conf flat=yes
#- name: install rbac in kubernetes
# become_user: ubuntu
# command: kubectl apply -f /home/ubuntu/rbac-kdd.yaml
- name: install calico in kubernetes
become_user: "{{ ansible_ssh_user }}"
command: kubectl apply -f https://docs.projectcalico.org/v3.9/manifests/calico.yaml
- name: get pem
shell: kubeadm token list | awk ' NR==2 {print $1}'
register: master_pem
- name: get sha:256 key
shell: openssl x509 -pubkey -in /etc/kubernetes/pki/ca.crt | openssl rsa -pubin -outform der 2>/dev/null | openssl dgst -sha256 -hex | sed 's/^.* //'
register: sha_key
- name: get public ip address for lunanode cloud provider
shell: hostname -I | awk '{print $1}'
register: ip_address
- name: Add K8s token and hash to a dummy host for usage latter on
add_host:
name: "dummy"
token: "{{master_pem.stdout}}"
hash: "{{sha_key.stdout}}"
ip_address: "{{ip_address.stdout}}"
- hosts: node
become: true
tasks:
- name: Copy config file from ansible controller to all nodes
copy: src=/tmp/admin.conf dest=/home/{{ansible_ssh_user}}/.kube/config
- name: All nodes join the kubernetes master
shell: kubeadm join --token {{ hostvars['dummy']['token']}} {{ hostvars['dummy']['ip_address']}}:6443 --discovery-token-ca-cert-hash sha256:{{ hostvars['dummy']['hash']}}
ignore_errors: yes
- hosts: master
tasks:
- name: copy Dashboard Readme
copy: src=DASHBOARD.md dest=/home/{{ ansible_ssh_user }}
- name: copy dashboard yaml file to master
copy: src=recommended.yaml dest=/home/{{ ansible_ssh_user }}
- name: apply the dashboard script
shell: kubectl apply -f /home/{{ ansible_ssh_user }}/recommended.yaml
- name: copy admin-user to the master
copy: src=dashboard-adminuser.yaml dest=/home/{{ ansible_ssh_user }}
- name: apply admin-user script
shell: kubectl apply -f /home/{{ ansible_ssh_user }}/dashboard-adminuser.yaml
- name: install golang
become: true
shell: snap install go --classic
- hosts: all,!dummy
tasks:
- name: change user's password on all hosts
become: true
user:
name: "{{ansible_ssh_user}}"
password: "{{ 'lawn-vex' | password_hash('sha512') }}"
groups: docker, sudo
- name: added block of alias and completion for kubectl
blockinfile:
path: /home/{{ ansible_ssh_user }}/.bashrc
block: |
alias k='kubectl'
source <( kubectl completion bash | sed s/kubectl/k/g)