xoxys.k3s/tasks/setup.yml
Robert Kaussow 1346207062
All checks were successful
continuous-integration/drone/pr Build is passing
rename var
2022-10-25 09:31:27 +02:00

63 lines
2.0 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: Set server address
command: >-
{{ __k3s_binary }} kubectl config set-cluster default
--server=https://{{ __k3s_server_ip }}:6443
--kubeconfig {{ __k3s_config_dir }}/k3s.yaml
changed_when: False
- name: Wait for initial setup
command: >-
{{ __k3s_binary }} 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
when: k3s_server | bool
- name: Patch existing resources
k8s:
kind: "{{ item.kind }}"
name: "{{ item.name }}"
kubeconfig: "{{ __k3s_config_dir }}/k3s.yaml"
state: patched
definition: "{{ item.definition }}"
loop: "{{ k3s_server_resource_patches }}"
loop_control:
label: "{{ item.kind }}/{{ item.name }}"
when: k3s_server | bool
- 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', '') }}"
when: ansible_hostname == hostvars[k3s_server_nodes[0]]['ansible_hostname']
become: True
become_user: root