Skip to content

Commit

Permalink
Rework Role Structure (#254)
Browse files Browse the repository at this point in the history
* Add more defaults
* Rename roles, covert download to airgap role
* Remove unnecessary gather_facts

Signed-off-by: Derek Nola <[email protected]>
  • Loading branch information
dereknola authored Nov 16, 2023
1 parent 52941b7 commit 1e633c5
Show file tree
Hide file tree
Showing 17 changed files with 65 additions and 67 deletions.
1 change: 0 additions & 1 deletion playbook/reset.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
---
- name: Undo cluster setup
hosts: k3s_cluster
gather_facts: true
become: true
tasks:
- name: Run K3s Uninstall script [server]
Expand Down
6 changes: 3 additions & 3 deletions playbook/site.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@
become: true
roles:
- role: prereq
- role: download
- role: airgap
- role: raspberrypi

- name: Setup K3S server
hosts: server
become: true
roles:
- role: k3s/server # noqa: role-name[path]
- role: k3s_server

- name: Setup K3S agent
hosts: agent
become: true
roles:
- role: k3s/agent # noqa: role-name[path]
- role: k3s_agent
6 changes: 2 additions & 4 deletions playbook/upgrade.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,13 @@
# Agents have no such limitation
- name: Upgrade K3s Servers
hosts: server
gather_facts: true
become: true
serial: 1
roles:
- role: upgrade
- role: k3s_upgrade

- name: Upgrade K3s Agents
hosts: agent
gather_facts: true
become: true
roles:
- role: upgrade
- role: k3s_upgrade
33 changes: 0 additions & 33 deletions roles/download/tasks/main.yml → roles/airgap/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -118,36 +118,3 @@
INSTALL_K3S_SKIP_DOWNLOAD: "true"
INSTALL_K3S_EXEC: "agent"
changed_when: true

- 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 [server]
when:
- "'server' in group_names"
- 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 }}"
changed_when: true

- name: Download k3s binary [agent]
when:
- "'agent' in group_names"
- 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
16 changes: 0 additions & 16 deletions roles/k3s/agent/tasks/main.yml

This file was deleted.

File renamed without changes.
36 changes: 36 additions & 0 deletions roles/k3s_agent/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -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
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,4 +1,24 @@
---
# 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 }}"
changed_when: true

- name: Init first server node
# Handle both hostname OR ip address being supplied in inventory
when: ansible_hostname == groups['server'][0] or groups['server'][0] in ansible_facts['all_ipv4_addresses']
Expand Down
2 changes: 2 additions & 0 deletions roles/k3s_upgrade/defaults/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
systemd_dir: /etc/systemd/system

Check warning on line 2 in roles/k3s_upgrade/defaults/main.yml

View workflow job for this annotation

GitHub Actions / Lint

var-naming[no-role-prefix]

Variables names from within roles should use k3s_upgrade_ as a prefix. (vars: systemd_dir)
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
---
- name: Set var defaults
when: systemd_dir is undefined
ansible.builtin.set_fact:
systemd_dir: /etc/systemd/system

# with_fileglob doesn't work with remote_src, it tries to find the file on the
# local control-plane instead of the remote host. Shell supports wildcards.
- name: Save current K3s service
Expand Down
2 changes: 2 additions & 0 deletions roles/prereq/defaults/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
api_port: 6443

Check warning on line 2 in roles/prereq/defaults/main.yml

View workflow job for this annotation

GitHub Actions / Lint

var-naming[no-role-prefix]

Variables names from within roles should use prereq_ as a prefix. (vars: api_port)
5 changes: 0 additions & 5 deletions roles/prereq/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,6 @@
- name: Populate service facts
ansible.builtin.service_facts:

- name: Assign api_port if not defined
when: api_port is undefined
ansible.builtin.set_fact:
api_port: 6443

- name: Allow UFW Exceptions
when:
- ansible_facts.services['ufw'] is defined
Expand Down

0 comments on commit 1e633c5

Please sign in to comment.