mirror of
https://github.com/k3s-io/k3s-ansible.git
synced 2025-12-25 00:12:37 +01:00
Rework Role Structure (#254)
* Add more defaults * Rename roles, covert download to airgap role * Remove unnecessary gather_facts Signed-off-by: Derek Nola <derek.nola@suse.com>
This commit is contained in:
4
roles/k3s_agent/defaults/main.yml
Normal file
4
roles/k3s_agent/defaults/main.yml
Normal file
@@ -0,0 +1,4 @@
|
||||
---
|
||||
k3s_server_location: "/var/lib/rancher/k3s"
|
||||
systemd_dir: "/etc/systemd/system"
|
||||
api_port: 6443
|
||||
36
roles/k3s_agent/tasks/main.yml
Normal file
36
roles/k3s_agent/tasks/main.yml
Normal file
@@ -0,0 +1,36 @@
|
||||
---
|
||||
# If airgapped, all K3s artifacts are already on the node.
|
||||
- name: Download K3s install script
|
||||
when: airgap_dir is undefined
|
||||
ansible.builtin.get_url:
|
||||
url: https://get.k3s.io/
|
||||
timeout: 120
|
||||
dest: /usr/local/bin/k3s-install.sh
|
||||
owner: root
|
||||
group: root
|
||||
mode: 0755
|
||||
|
||||
- name: Download K3s binary
|
||||
when: airgap_dir is undefined
|
||||
ansible.builtin.command:
|
||||
cmd: /usr/local/bin/k3s-install.sh
|
||||
environment:
|
||||
INSTALL_K3S_SKIP_START: "true"
|
||||
INSTALL_K3S_VERSION: "{{ k3s_version }}"
|
||||
INSTALL_K3S_EXEC: "agent"
|
||||
changed_when: true
|
||||
|
||||
- name: Copy K3s service file
|
||||
ansible.builtin.template:
|
||||
src: "k3s-agent.service.j2"
|
||||
dest: "{{ systemd_dir }}/k3s-agent.service"
|
||||
owner: root
|
||||
group: root
|
||||
mode: 0755
|
||||
|
||||
- name: Enable and check K3s service
|
||||
ansible.builtin.systemd:
|
||||
name: k3s-agent
|
||||
daemon_reload: true
|
||||
state: started
|
||||
enabled: true
|
||||
29
roles/k3s_agent/templates/k3s-agent.service.j2
Normal file
29
roles/k3s_agent/templates/k3s-agent.service.j2
Normal file
@@ -0,0 +1,29 @@
|
||||
[Unit]
|
||||
Description=Lightweight Kubernetes
|
||||
Documentation=https://k3s.io
|
||||
Wants=network-online.target
|
||||
After=network-online.target
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
|
||||
[Service]
|
||||
Type=notify
|
||||
EnvironmentFile=-/etc/default/%N
|
||||
EnvironmentFile=-/etc/sysconfig/%N
|
||||
EnvironmentFile=-/etc/systemd/system/k3s.service.env
|
||||
KillMode=process
|
||||
Delegate=yes
|
||||
# Having non-zero Limit*s causes performance problems due to accounting overhead
|
||||
# in the kernel. We recommend using cgroups to do container-local accounting.
|
||||
LimitNOFILE=1048576
|
||||
LimitNPROC=infinity
|
||||
LimitCORE=infinity
|
||||
TasksMax=infinity
|
||||
TimeoutStartSec=0
|
||||
Restart=always
|
||||
RestartSec=5s
|
||||
ExecStartPre=/bin/sh -xc '! /usr/bin/systemctl is-enabled --quiet nm-cloud-setup.service'
|
||||
ExecStartPre=-/sbin/modprobe br_netfilter
|
||||
ExecStartPre=-/sbin/modprobe overlay
|
||||
ExecStart=/usr/local/bin/k3s agent --data-dir {{ k3s_server_location }} --server https://{{ api_endpoint }}:{{ api_port }} --token {{ token }} {{ extra_agent_args }}
|
||||
Reference in New Issue
Block a user