Skip to content

Commit 328f617

Browse files
committed
Inject installation envs for install script
Signed-off-by: Derek Nola <derek.nola@suse.com>
1 parent 5a19438 commit 328f617

7 files changed

Lines changed: 23 additions & 10 deletions

File tree

inventory-sample.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ k3s_cluster:
2626
# Optional vars
2727
# extra_server_args: ""
2828
# extra_agent_args: ""
29+
# extra_install_envs: { 'INSTALL_K3S_SKIP_SELINUX_RPM': 'true' }
2930
# cluster_context: k3s-ansible
3031
# api_port: 6443
3132
# k3s_server_location: /var/lib/rancher/k3s

roles/k3s_agent/defaults/main.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ k3s_server_location: "/var/lib/rancher/k3s" # noqa var-naming[no-role-prefix]
44
systemd_dir: "/etc/systemd/system" # noqa var-naming[no-role-prefix]
55
api_port: 6443 # noqa var-naming[no-role-prefix]
66
extra_agent_args: "" # noqa var-naming[no-role-prefix]
7+
extra_install_envs: {} # noqa var-naming[no-role-prefix]

roles/k3s_agent/tasks/main.yml

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,14 @@
2929
- name: Download K3s binary
3030
ansible.builtin.command:
3131
cmd: /usr/local/bin/k3s-install.sh
32-
environment:
33-
INSTALL_K3S_SKIP_START: "true"
34-
INSTALL_K3S_VERSION: "{{ k3s_version }}"
35-
INSTALL_K3S_EXEC: "agent"
32+
# Ensures that extra_install_envs are combined with required env vars
33+
environment: >-
34+
{{ extra_install_envs | combine({
35+
"INSTALL_K3S_SKIP_START": "true",
36+
"INSTALL_K3S_SYSTEMD_DIR": systemd_dir,
37+
"INSTALL_K3S_VERSION": k3s_version,
38+
"INSTALL_K3S_EXEC": "agent"
39+
}) }}
3640
changed_when: true
3741

3842
- name: Setup optional config file

roles/k3s_server/defaults/main.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@ server_group: server # noqa var-naming[no-role-prefix]
99
agent_group: agent # noqa var-naming[no-role-prefix]
1010
use_external_database: false # noqa var-naming[no-role-prefix]
1111
extra_server_args: "" # noqa var-naming[no-role-prefix]
12+
extra_install_envs: {} # noqa var-naming[no-role-prefix]

roles/k3s_server/tasks/main.yml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,12 @@
2929
- name: Download K3s binary
3030
ansible.builtin.command:
3131
cmd: /usr/local/bin/k3s-install.sh
32-
environment:
33-
INSTALL_K3S_SKIP_START: "true"
34-
INSTALL_K3S_VERSION: "{{ k3s_version }}"
32+
# Ensures that extra_install_envs are combined with required env vars
33+
environment: >-
34+
{{ extra_install_envs | combine({
35+
"INSTALL_K3S_SKIP_START": "true",
36+
"INSTALL_K3S_VERSION": k3s_version,
37+
}) }}
3538
changed_when: true
3639

3740
- name: Add K3s autocomplete to user bashrc

roles/k3s_upgrade/defaults/main.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@
22
systemd_dir: /etc/systemd/system # noqa var-naming[no-role-prefix]
33
server_group: server # noqa var-naming[no-role-prefix]
44
agent_group: agent # noqa var-naming[no-role-prefix]
5+
extra_install_envs: {} # noqa var-naming[no-role-prefix]

roles/k3s_upgrade/tasks/main.yml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,11 @@
3535
- name: Install new K3s Version
3636
ansible.builtin.command:
3737
cmd: /usr/local/bin/k3s-install.sh
38-
environment:
39-
INSTALL_K3S_SKIP_START: "true"
40-
INSTALL_K3S_VERSION: "{{ k3s_version }}"
38+
environment: >-
39+
{{ extra_install_envs | combine({
40+
"INSTALL_K3S_SKIP_START": "true",
41+
"INSTALL_K3S_VERSION": k3s_version,
42+
}) }}
4143
changed_when: true
4244

4345
- name: Restore K3s service

0 commit comments

Comments
 (0)