Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions inventory-sample.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ k3s_cluster:
# Optional vars
# extra_server_args: ""
# extra_agent_args: ""
# extra_install_envs: { 'INSTALL_K3S_SKIP_SELINUX_RPM': 'true' }
# cluster_context: k3s-ansible
# api_port: 6443
# k3s_server_location: /var/lib/rancher/k3s
Expand Down
1 change: 1 addition & 0 deletions roles/k3s_agent/defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ k3s_server_location: "/var/lib/rancher/k3s" # noqa var-naming[no-role-prefix]
systemd_dir: "/etc/systemd/system" # noqa var-naming[no-role-prefix]
api_port: 6443 # noqa var-naming[no-role-prefix]
extra_agent_args: "" # noqa var-naming[no-role-prefix]
extra_install_envs: {} # noqa var-naming[no-role-prefix]
16 changes: 11 additions & 5 deletions roles/k3s_agent/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
---
- name: Get k3s installed version

Check warning on line 2 in roles/k3s_agent/tasks/main.yml

View workflow job for this annotation

GitHub Actions / Lint

var-naming[no-role-prefix]

Variables names from within roles should use k3s_agent_ as a prefix. (register: k3s_version_output)
ansible.builtin.command: k3s --version
register: k3s_version_output
changed_when: false
ignore_errors: true

- name: Set k3s installed version

Check warning on line 8 in roles/k3s_agent/tasks/main.yml

View workflow job for this annotation

GitHub Actions / Lint

var-naming[no-role-prefix]

Variables names from within roles should use k3s_agent_ as a prefix. (set_fact: installed_k3s_version)
when: not ansible_check_mode and k3s_version_output.rc == 0
ansible.builtin.set_fact:
installed_k3s_version: "{{ k3s_version_output.stdout_lines[0].split(' ')[2] }}"
Expand All @@ -27,12 +27,18 @@
mode: "0755"

- name: Download K3s binary
ansible.builtin.command:
# For some reason, ansible-lint thinks using enviroment with command is an error
# even though its valid https://ansible.readthedocs.io/projects/lint/rules/inline-env-var/#correct-code
ansible.builtin.command: # noqa inline-env-var
cmd: /usr/local/bin/k3s-install.sh
environment:
INSTALL_K3S_SKIP_START: "true"
INSTALL_K3S_VERSION: "{{ k3s_version }}"
INSTALL_K3S_EXEC: "agent"
# Ensures that extra_install_envs are combined with required env vars
environment: >-
{{ extra_install_envs | combine({
"INSTALL_K3S_SKIP_START": "true",
"INSTALL_K3S_SYSTEMD_DIR": systemd_dir,
"INSTALL_K3S_VERSION": k3s_version,
"INSTALL_K3S_EXEC": "agent"
}) }}
changed_when: true

- name: Setup optional config file
Expand All @@ -43,14 +49,14 @@
path: "/etc/rancher/k3s"
mode: "0755"
state: directory
- name: Copy config values

Check warning on line 52 in roles/k3s_agent/tasks/main.yml

View workflow job for this annotation

GitHub Actions / Lint

var-naming[no-role-prefix]

Variables names from within roles should use k3s_agent_ as a prefix. (register: _agent_config_result)
ansible.builtin.copy:
content: "{{ agent_config_yaml }}"
dest: "/etc/rancher/k3s/config.yaml"
mode: "0644"
register: _agent_config_result

- name: Get the token from the first server

Check warning on line 59 in roles/k3s_agent/tasks/main.yml

View workflow job for this annotation

GitHub Actions / Lint

var-naming[no-role-prefix]

Variables names from within roles should use k3s_agent_ as a prefix. (set_fact: token)
ansible.builtin.set_fact:
token: "{{ hostvars[groups[server_group][0]].token }}"

Expand Down
1 change: 1 addition & 0 deletions roles/k3s_server/defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ server_group: server # noqa var-naming[no-role-prefix]
agent_group: agent # noqa var-naming[no-role-prefix]
use_external_database: false # noqa var-naming[no-role-prefix]
extra_server_args: "" # noqa var-naming[no-role-prefix]
extra_install_envs: {} # noqa var-naming[no-role-prefix]
13 changes: 9 additions & 4 deletions roles/k3s_server/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
---
- name: Get k3s installed version

Check warning on line 2 in roles/k3s_server/tasks/main.yml

View workflow job for this annotation

GitHub Actions / Lint

var-naming[no-role-prefix]

Variables names from within roles should use k3s_server_ as a prefix. (register: k3s_version_output)
ansible.builtin.command: k3s --version
register: k3s_version_output
changed_when: false
ignore_errors: true

- name: Set k3s installed version

Check warning on line 8 in roles/k3s_server/tasks/main.yml

View workflow job for this annotation

GitHub Actions / Lint

var-naming[no-role-prefix]

Variables names from within roles should use k3s_server_ as a prefix. (set_fact: installed_k3s_version)
when: not ansible_check_mode and k3s_version_output.rc == 0
ansible.builtin.set_fact:
installed_k3s_version: "{{ k3s_version_output.stdout_lines[0].split(' ')[2] }}"
Expand All @@ -27,11 +27,16 @@
mode: "0755"

- name: Download K3s binary
ansible.builtin.command:
# For some reason, ansible-lint thinks using enviroment with command is an error
# even though its valid https://ansible.readthedocs.io/projects/lint/rules/inline-env-var/#correct-code
ansible.builtin.command: # noqa inline-env-var
cmd: /usr/local/bin/k3s-install.sh
environment:
INSTALL_K3S_SKIP_START: "true"
INSTALL_K3S_VERSION: "{{ k3s_version }}"
# Ensures that extra_install_envs are combined with required env vars
environment: >-
{{ extra_install_envs | combine({
"INSTALL_K3S_SKIP_START": "true",
"INSTALL_K3S_VERSION": k3s_version,
}) }}
changed_when: true

- name: Add K3s autocomplete to user bashrc
Expand All @@ -49,7 +54,7 @@
path: "/etc/rancher/k3s"
mode: "0755"
state: directory
- name: Copy config values

Check warning on line 57 in roles/k3s_server/tasks/main.yml

View workflow job for this annotation

GitHub Actions / Lint

var-naming[no-role-prefix]

Variables names from within roles should use k3s_server_ as a prefix. (register: _server_config_result)
ansible.builtin.copy:
content: "{{ server_config_yaml }}"
dest: "/etc/rancher/k3s/config.yaml"
Expand Down
1 change: 1 addition & 0 deletions roles/k3s_upgrade/defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
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]
extra_install_envs: {} # noqa var-naming[no-role-prefix]
12 changes: 8 additions & 4 deletions roles/k3s_upgrade/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,15 @@
loop: "{{ k3s_service_files.files }}"

- name: Install new K3s Version
ansible.builtin.command:
# For some reason, ansible-lint thinks using enviroment with command is an error
# even though its valid https://ansible.readthedocs.io/projects/lint/rules/inline-env-var/#correct-code
ansible.builtin.command: # noqa inline-env-var
cmd: /usr/local/bin/k3s-install.sh
environment:
INSTALL_K3S_SKIP_START: "true"
INSTALL_K3S_VERSION: "{{ k3s_version }}"
environment: >-
{{ extra_install_envs | combine({
"INSTALL_K3S_SKIP_START": "true",
"INSTALL_K3S_VERSION": k3s_version,
}) }}
changed_when: true

- name: Restore K3s service
Expand Down
Loading