xoxys.k3s/tasks/setup.yml
2022-10-03 22:58:05 +02:00

60 lines
1.5 KiB
YAML

---
- 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:
path: "{{ k3s_data_dir }}/server/node-token"
- name: Read node-token from server
slurp:
path: "{{ k3s_data_dir }}/server/node-token"
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
--kubeconfig /etc/rancher/k3s/k3s.yaml
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:
src: /etc/rancher/k3s/k3s.yaml
dest: "{{ ansible_user_dir }}/.kube/config"
remote_src: True
owner: "{{ ansible_user }}"
group: "{{ ansible_user }}"
mode: "preserve"
become: True
become_user: root