xoxys.k3s/tasks/setup.yml

79 lines
2.3 KiB
YAML
Raw Normal View History

2022-10-03 20:58:05 +00:00
---
- block:
- name: Copy K3s service file
template:
src: "etc/systemd/system/k3s.service.j2"
dest: "{{ __k3s_service_file }}"
owner: root
group: root
mode: 0644
notify: __k3s_restart
- name: Force restart
meta: flush_handlers
- name: Ensure K3s service is up and running
service:
name: k3s
daemon_reload: True
enabled: True
state: started
- name: Wait for node-token
wait_for:
2022-10-05 20:54:36 +00:00
path: "{{ __k3s_data_dir }}/server/node-token"
2022-10-03 20:58:05 +00:00
- name: Read node-token from server
slurp:
2022-10-05 20:54:36 +00:00
path: "{{ __k3s_data_dir }}/server/node-token"
2022-10-03 20:58:05 +00:00
register: __k3s_node_token
- name: Store server node-token
set_fact:
token: "{{ __k3s_node_token.content | b64decode | regex_replace('\n', '') }}"
- name: Set server address
command: >-
k3s kubectl config set-cluster default
--server=https://{{ __k3s_server_ip }}:6443
2022-10-05 20:54:36 +00:00
--kubeconfig {{ __k3s_config_dir }}/k3s.yaml
2022-10-03 20:58:05 +00:00
changed_when: False
- name: Create directory .kube
file:
path: "{{ ansible_user_dir }}/.kube"
state: directory
owner: "{{ ansible_user }}"
group: "{{ ansible_user }}"
mode: 0740
- name: Copy kube config to user home
copy:
2022-10-05 20:54:36 +00:00
src: "{{ __k3s_config_dir }}/k3s.yaml"
2022-10-03 20:58:05 +00:00
dest: "{{ ansible_user_dir }}/.kube/config"
remote_src: True
owner: "{{ ansible_user }}"
group: "{{ ansible_user }}"
mode: "preserve"
2022-10-05 20:54:36 +00:00
- name: Wait for initial setup
command: >-
kubectl get deployment coredns
-n kube-system
-o go-template={% raw %}'{{ .status.availableReplicas }}'{% endraw %}
register: __k3s_init_setup
until: __k3s_init_setup.rc == 0 and __k3s_init_setup.stdout == "1"
retries: 6
delay: 10
changed_when: False
- name: Remove auto-deploying manifests
file:
path: "{{ __k3s_manifests_dir }}/{{ item.dest | default(item.url) | default(item) | basename | replace('.j2', '') }}"
state: absent
loop: "{{ k3s_server_manifests_urls + k3s_server_manifests_templates }}"
loop_control:
label: "{{ __k3s_manifests_dir }}/{{ item.dest | default(item.url) | default(item) | basename | replace('.j2', '') }}"
2022-10-03 20:58:05 +00:00
become: True
become_user: root