Robert Kaussow
47b2e4bb1e
All checks were successful
continuous-integration/drone/push Build is passing
100 lines
3.0 KiB
YAML
100 lines
3.0 KiB
YAML
---
|
|
- block:
|
|
- name: Import Rancher public key
|
|
rpm_key:
|
|
state: present
|
|
key: https://rpm.rancher.io/public.key
|
|
|
|
- name: Ensure dependencies are installed
|
|
package:
|
|
name: "{{ item }}"
|
|
state: present
|
|
loop: "{{ k3s_packages + k3s_packages_extra }}"
|
|
|
|
- name: Check if cluster is installed
|
|
stat:
|
|
path: "{{ __k3s_config_dir }}/k3s.yaml"
|
|
register: __k3s_installed
|
|
|
|
- name: Prepare directory structure
|
|
file:
|
|
path: "{{ item }}"
|
|
owner: root
|
|
group: root
|
|
mode: 0700
|
|
state: directory
|
|
loop:
|
|
- "{{ __k3s_config_dir }}"
|
|
- "{{ __k3s_config_dir }}/server"
|
|
- "{{ __k3s_data_dir }}"
|
|
- "{{ __k3s_manifests_dir }}"
|
|
- "{{ __k3s_log_dir }}"
|
|
|
|
- name: Download K3s binary
|
|
get_url:
|
|
url: https://github.com/k3s-io/k3s/releases/download/v{{ k3s_version }}/k3s
|
|
checksum: sha256:https://github.com/k3s-io/k3s/releases/download/v{{ k3s_version }}/sha256sum-amd64.txt
|
|
dest: /usr/local/bin/k3s
|
|
timeout: 30
|
|
owner: root
|
|
group: root
|
|
mode: 0755
|
|
notify: __k3s_restart
|
|
|
|
- name: Copy K3s config file
|
|
template:
|
|
src: "etc/rancher/k3s/config.yaml.j2"
|
|
dest: "{{ __k3s_config_dir }}/config.yaml"
|
|
owner: root
|
|
group: root
|
|
mode: 0600
|
|
notify: __k3s_restart
|
|
|
|
- name: Copy K3s kubelet config file
|
|
template:
|
|
src: "etc/rancher/k3s/kubelet.yaml.j2"
|
|
dest: "{{ __k3s_config_dir }}/kubelet.yaml"
|
|
owner: root
|
|
group: root
|
|
mode: 0600
|
|
notify: __k3s_restart
|
|
|
|
- name: Copy K3s server config files
|
|
template:
|
|
src: "etc/rancher/k3s/server/{{ item }}.j2"
|
|
dest: "{{ __k3s_config_dir }}/server/{{ item }}"
|
|
owner: root
|
|
group: root
|
|
mode: 0600
|
|
loop:
|
|
- admission-config.yaml
|
|
when: k3s_server | bool
|
|
notify: __k3s_restart
|
|
|
|
- name: Copy auto-deploying manifests to the server
|
|
template:
|
|
src: "{{ item }}"
|
|
dest: "{{ __k3s_manifests_dir }}/{{ item | basename | replace('.j2', '') }}"
|
|
mode: 0644
|
|
loop: "{{ k3s_server_manifests_templates }}"
|
|
loop_control:
|
|
label: "{{ __k3s_manifests_dir }}/{{ item | basename | replace('.j2', '') }}"
|
|
when:
|
|
- ansible_hostname == hostvars[k3s_server_nodes[0]]['ansible_hostname']
|
|
- not __k3s_installed.stat.exists
|
|
|
|
- name: Download auto-deploying manifests to the server
|
|
get_url:
|
|
url: "{{ item.url }}"
|
|
dest: "{{ __k3s_manifests_dir }}/{{ item.dest | default(item.url | basename) }}"
|
|
timeout: 30
|
|
mode: 0644
|
|
loop: "{{ k3s_server_manifests_urls }}"
|
|
loop_control:
|
|
label: "{{ __k3s_manifests_dir }}/{{ item.dest | default(item.url | basename) }}"
|
|
when:
|
|
- ansible_hostname == hostvars[k3s_server_nodes[0]]['ansible_hostname']
|
|
- not __k3s_installed.stat.exists
|
|
become: True
|
|
become_user: root
|