Commit cd725780 authored by Nicholas Malcolm's avatar Nicholas Malcolm Committed by Derek Nola
Browse files

Move k3s_server_location to inventory vars



- All environemt variables are now in one place
- Add --data-dir option to agent and init  service

Signed-off-by: default avatarDerek Nola <derek.nola@suse.com>
parent 5b3e2a5d
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -13,6 +13,7 @@ k3s_cluster:
    ansible_port: 22
    ansible_user: debian
    k3s_version: v1.25.5+k3s2
    k3s_server_location: /var/lib/rancher/k3s
    systemd_dir: /etc/systemd/system
    api_endpoint: "{{ hostvars[groups['server'][0]]['ansible_host'] | default(groups['server'][0]) }}"
    api_port: 6443
+1 −1
Original line number Diff line number Diff line
@@ -7,7 +7,7 @@ After=network-online.target
Type=notify
ExecStartPre=-/sbin/modprobe br_netfilter
ExecStartPre=-/sbin/modprobe overlay
ExecStart=/usr/local/bin/k3s agent --server https://{{ api_endpoint }}:{{ api_port }} --token {{ hostvars[groups['server'][0]]['token'] }} {{ extra_agent_args | default("") }}
ExecStart=/usr/local/bin/k3s agent --data-dir {{ k3s_server_location }} --server https://{{ api_endpoint }}:{{ api_port }} --token {{ hostvars[groups['server'][0]]['token'] }} {{ extra_agent_args | default("") }}
KillMode=process
Delegate=yes
# Having non-zero Limit*s causes performance problems due to accounting overhead
+0 −2
Original line number Diff line number Diff line
---
k3s_server_location: /var/lib/rancher/k3s
+4 −3
Original line number Diff line number Diff line
@@ -10,7 +10,8 @@
      ansible.builtin.command:
        cmd: >
          systemd-run -p RestartSec=2 -p Restart=on-failure --unit=k3s-init k3s server
          --cluster-init --tls-san {{ api_endpoint }} {{ extra_server_args | default('') }}
          --cluster-init --tls-san {{ api_endpoint }} --data-dir {{ k3s_server_location }}
          {{ extra_server_args | default('') }}
        creates: "{{ systemd_dir }}/k3s-init.service"
      when: groups['server'] | length > 1

@@ -18,7 +19,7 @@
      ansible.builtin.command:
        cmd: >
          systemd-run -p RestartSec=2 -p Restart=on-failure --unit=k3s-init k3s server
           --tls-san {{ api_endpoint }} { extra_server_args | default('') }}
           --tls-san {{ api_endpoint }} --data-dir {{ k3s_server_location }} { extra_server_args | default('') }}
        creates: "{{ systemd_dir }}/k3s-init.service"
      when: groups['server'] | length == 1

@@ -84,7 +85,7 @@
    cmd: >
      systemd-run -p RestartSec=2 -p Restart=on-failure --unit=k3s-init k3s server --token "{{ hostvars[groups['server'][0]]['token'] }}"
      --server https://{{ hostvars[groups['server'][0]]['ansible_host'] | default(groups['server'][0]) }}:{{ api_port }}
          {{ extra_server_args | default('') }}
      --data-dir {{ k3s_server_location }} {{ extra_server_args | default('') }}
    creates: "{{ systemd_dir }}/k3s-init.service"
  when: ansible_hostname != groups['server'][0]

+1 −6
Original line number Diff line number Diff line
---
- name: Clean previous runs of k3s-init
  command: systemctl reset-failed k3s-init
  failed_when: false
  changed_when: false

- name: Disable services
  ansible.builtin.systemd:
    name: "{{ item }}"
@@ -40,7 +35,7 @@
    - "{{ systemd_dir }}/k3s-agent.service"
    - /etc/rancher/k3s
    - /var/lib/kubelet
    - /var/lib/rancher/k3s
    - "{{ k3s_server_location }}"

- name: Systemd daemon reload
  ansible.builtin.systemd: