This repository has been archived by the owner on Apr 29, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathk0s.yml
140 lines (120 loc) · 4.18 KB
/
k0s.yml
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
#!/usr/local/bin/ansible-playbook
# Purpose:
# - build k0s on target host
############################################################################
# Localhost Prep Tasks
- name: MSIO | Kargo | K3s Deploy | ansible/run-k0s
hosts: kargo
vars:
module: "k0s"
ansible_name_module: "Konductor | CCIO | {{ ansible_distribution }} | {{ module }}"
vars_files:
- 'vars/global.yml'
- 'vars/{{ ansible_os_family }}.yml'
tasks:
############################################################################
# Kargo Tasks
- name: Check for latest release of k0s
delegate_to: self
shell: curl -s https://api.github.com/repos/k0sproject/k0s/releases/latest | awk -F '["v,+]' '/tag_name/{print $5}'
register: k0s_version
- name: Purge pre-existing k0s binaries
file:
state: directory
path: /root/.k0s
mode: 0644
# - name: Purge pre-existing k0s binaries
# file:
# state: absent
# path: /usr/bin/k0s
- name: 'Download k0s binary {{ k0s_version }}'
get_url:
# url: https://github.com/k0sproject/k0s/releases/download/$version/k0s-{{ k0s_version }}-amd64
url: https://github.com/k0sproject/k0s/releases/download/v0.9.0-rc1/k0s-v0.9.0-rc1-amd64
dest: /usr/bin/k0s
owner: root
group: root
mode: 0755
- name: Configure k0s bash completion
shell: '/usr/bin/k0s completion bash > /etc/bash_completion.d/k0s'
# - name: Create kubectl symlink
# file:
# src: /usr/local/bin/k0s
# dest: /usr/local/bin/kubectl
# state: link
# - name: Create crictl symlink
# file:
# src: /usr/local/bin/k0s
# dest: /usr/local/bin/crictl
# state: link
####### Place k0s.yaml
- name: Write K0s Systemd Service file
template:
src: "k0s/k0s.yaml.j2"
dest: "/root/.k0s/k0s.yaml"
owner: root
group: root
mode: 0755
####### Place k0s .kube/config
- name: Write K0s Systemd Service file
template:
src: "systemd/k0s.service.j2"
dest: "/etc/systemd/system/k0s.service"
owner: root
group: root
mode: 0755
- name: Enable K3s service
systemd:
name: k0s
daemon_reload: yes
enabled: yes
- name: '{{ ansible_name_module }} | file | {{ ansible_distribution }} | Create .kube directory'
file:
path: /root/.kube
state: directory
owner: "root"
mode: "u=rwx,g=rx,o="
# - wait_for:
# path: "/etc/rancher/k0s/k0s.yaml"
# - name: Copy config file to .kube/config
# copy:
# src: /etc/rancher/k0s/k0s.yaml
# dest: /root/.kube/config
# remote_src: yes
# owner: "root"
# mode: "u=rw,g=,o="
# - name: 'Replace https://localhost:6443 by https://{{ kargo_addr_n01 }}:6443'
# command: >-
# k0s kubectl config set-cluster default
# --server=https://{{ kargo_addr_n01 }}:6443
# --kubeconfig /root/.kube/config
# changed_when: true
# ####### Fetch k0s .kube/config
# - name: '{{ ansible_name_module }} | fetch | copy config to localhost .kube/config'
# fetch:
# src: "/etc/rancher/k0s/k0s.yaml"
# dest: "{{ ansible_env.HOME }}/.kube/config"
# flat: yes
# - name: '{{ ansible_name_module }} | lineinfile | find replace localhost/{{ kargo_host }}'
# delegate_to: konductor
# lineinfile:
# dest: "{{ ansible_env.HOME }}/.kube/config"
# regexp: "{{ item.match }}"
# line: "{{ item.new }}"
# with_items:
# - { match: ' server: https://127.0.0.1:6443', new: ' server: https://{{ kargo_host }}:6443' }
# ####### Copy k0s .kube/config to localhost .kube/config
# - name: '{{ ansible_name_module }} | fetch | copy config to localhost .kube/config'
# delegate_to: host
# file:
# path: "{{ ansible_env.HOME }}/.kube"
# state: directory
# owner: "root"
# mode: "u=rwx,g=rx,o="
# ####### Copy k0s .kube/config to localhost .kube/config
# - name: '{{ ansible_name_module }} | fetch | copy config to localhost .kube/config'
# delegate_to: host
# copy:
# src: "/root/.kube/config"
# dest: "{{ ansible_env.HOME }}/.kube/config.kargo"
# mode: 0755