Make agent and server groups configurable (#331)

* Make agent and server groups configurable

Signed-off-by: Meagan Harris <thewitch@siliconsorceress.com>

* Fix typo in upgrade role

Co-authored-by: Derek Nola <derek.nola@suse.com>
Signed-off-by: Meagan Harris <47128741+simagick@users.noreply.github.com>

---------

Signed-off-by: Meagan Harris <thewitch@siliconsorceress.com>
Signed-off-by: Meagan Harris <47128741+simagick@users.noreply.github.com>
Co-authored-by: Derek Nola <derek.nola@suse.com>
This commit is contained in:
Meagan Harris 2024-06-04 13:06:14 -04:00 committed by GitHub
parent af29159231
commit 006653f3ff
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 15 additions and 11 deletions

View File

@ -5,3 +5,5 @@ api_port: 6443 # noqa var-naming[no-role-prefix]
kubeconfig: ~/.kube/config.new # noqa var-naming[no-role-prefix] kubeconfig: ~/.kube/config.new # noqa var-naming[no-role-prefix]
user_kubectl: true # noqa var-naming[no-role-prefix] user_kubectl: true # noqa var-naming[no-role-prefix]
cluster_context: k3s-ansible # noqa var-naming[no-role-prefix] cluster_context: k3s-ansible # noqa var-naming[no-role-prefix]
server_group: server # noqa var-naming[no-role-prefix]
agent_group: agent # noqa var-naming[no-role-prefix]

View File

@ -55,10 +55,10 @@
mode: "0644" mode: "0644"
- name: Init first server node - name: Init first server node
when: inventory_hostname == groups['server'][0] when: inventory_hostname == groups[server_group][0]
block: block:
- name: Copy K3s service file [Single] - name: Copy K3s service file [Single]
when: groups['server'] | length == 1 when: groups[server_group] | length == 1
ansible.builtin.template: ansible.builtin.template:
src: "k3s-single.service.j2" src: "k3s-single.service.j2"
dest: "{{ systemd_dir }}/k3s.service" dest: "{{ systemd_dir }}/k3s.service"
@ -67,7 +67,7 @@
mode: "0644" mode: "0644"
- name: Copy K3s service file [HA] - name: Copy K3s service file [HA]
when: groups['server'] | length > 1 when: groups[server_group] | length > 1
ansible.builtin.template: ansible.builtin.template:
src: "k3s-cluster-init.service.j2" src: "k3s-cluster-init.service.j2"
dest: "{{ systemd_dir }}/k3s.service" dest: "{{ systemd_dir }}/k3s.service"
@ -90,7 +90,7 @@
enabled: true enabled: true
- name: Pause to allow first server startup - name: Pause to allow first server startup
when: (groups['server'] | length) > 1 when: (groups[server_group] | length) > 1
ansible.builtin.pause: ansible.builtin.pause:
seconds: 10 seconds: 10
@ -144,11 +144,11 @@
- name: Start other server if any and verify status - name: Start other server if any and verify status
when: when:
- (groups['server'] | length) > 1 - (groups[server_group] | length) > 1
- inventory_hostname != groups['server'][0] - inventory_hostname != groups[server_group][0]
block: block:
- name: Copy K3s service file [HA] - name: Copy K3s service file [HA]
when: groups['server'] | length > 1 when: groups[server_group] | length > 1
ansible.builtin.template: ansible.builtin.template:
src: "k3s-ha.service.j2" src: "k3s-ha.service.j2"
dest: "{{ systemd_dir }}/k3s.service" dest: "{{ systemd_dir }}/k3s.service"
@ -164,12 +164,12 @@
enabled: true enabled: true
- name: Verify that all server nodes joined - name: Verify that all server nodes joined
when: (groups['server'] | length) > 1 when: (groups[server_group] | length) > 1
ansible.builtin.command: ansible.builtin.command:
cmd: > cmd: >
k3s kubectl get nodes -l "node-role.kubernetes.io/control-plane=true" -o=jsonpath="{.items[*].metadata.name}" k3s kubectl get nodes -l "node-role.kubernetes.io/control-plane=true" -o=jsonpath="{.items[*].metadata.name}"
register: nodes register: nodes
until: nodes.rc == 0 and (nodes.stdout.split() | length) == (groups['server'] | length) until: nodes.rc == 0 and (nodes.stdout.split() | length) == (groups[server_group] | length)
retries: 20 retries: 20
delay: 10 delay: 10
changed_when: false changed_when: false

View File

@ -1,2 +1,4 @@
--- ---
systemd_dir: /etc/systemd/system # noqa var-naming[no-role-prefix] systemd_dir: /etc/systemd/system # noqa var-naming[no-role-prefix]
server_group: server # noqa var-naming[no-role-prefix]
agent_group: agent # noqa var-naming[no-role-prefix]

View File

@ -54,14 +54,14 @@
loop: "{{ k3s_service_files.files }}" loop: "{{ k3s_service_files.files }}"
- name: Restart K3s service [server] - name: Restart K3s service [server]
when: "'server' in group_names" when: "server_group in group_names"
ansible.builtin.systemd: ansible.builtin.systemd:
state: restarted state: restarted
daemon_reload: true daemon_reload: true
name: k3s name: k3s
- name: Restart K3s service [agent] - name: Restart K3s service [agent]
when: "'agent' in group_names" when: "agent_group in group_names"
ansible.builtin.systemd: ansible.builtin.systemd:
state: restarted state: restarted
daemon_reload: true daemon_reload: true