Skip to content

Commit b49b22c

Browse files
committed
Added (very hacky) k3s token generation
1 parent 824e117 commit b49b22c

File tree

5 files changed

+19
-3
lines changed

5 files changed

+19
-3
lines changed

ansible/roles/k3s/files/start_k3s.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,13 @@
1212
ansible.builtin.lineinfile:
1313
path: "/etc/systemd/system/{{ service_name }}.service.env"
1414
line: "K3S_TOKEN={{ k3s_token }}"
15+
1516
- name: Add server url to agents
1617
ansible.builtin.lineinfile:
1718
path: "/etc/systemd/system/{{ service_name }}.service.env"
1819
line: "K3S_URL=https://{{ k3s_server_name }}:6443"
1920
when: k3s_node_type == "agent"
21+
2022
- name: Start k3s service
2123
ansible.builtin.systemd:
2224
name: "{{ service_name }}"

ansible/roles/k3s/tasks/main.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
group: root
1010
mode: "0755"
1111

12-
- name: Install k3s server
12+
- name: Install k3s
1313
ansible.builtin.shell:
1414
cmd: /usr/local/bin/k3s-install.sh
1515
environment:

ansible/roles/passwords/tasks/main.yml

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,19 @@
77
delegate_to: localhost
88
run_once: true
99

10+
- name: Generate k3s token
11+
ansible.builtin.set_fact:
12+
k3s_token_secret: ""
13+
14+
- name: Generate k3s token and add to terraform
15+
vars:
16+
token: "{{ lookup('ansible.builtin.password', '/dev/null', length=64) }}"
17+
replace:
18+
path: "{{ lookup('env', 'APPLIANCES_ENVIRONMENT_ROOT') }}/terraform/variables.tf"
19+
regexp: "k3s_token_replace_me"
20+
replace: "{{ token }}"
21+
22+
1023
# - name: Ensure munge key directory exists
1124
# file:
1225
# state: directory
@@ -17,4 +30,4 @@
1730
# copy:
1831
# content: "{{ lookup('password', '/dev/null chars=ascii_letters,digits,hexdigits,punctuation') }}"
1932
# dest: "{{ openhpc_passwords_mungekey_output_path }}"
20-
# force: false
33+
# force: false

environments/skeleton/{{cookiecutter.environment}}/terraform/compute/variables.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,6 @@ variable "security_group_ids" {
6969
}
7070

7171
variable "k3s_token" {
72-
description = "Random cryptographically secure string for K3s token"
72+
description = "Random cryptographically secure string for K3s token (must be set by ../compute.tf)"
7373
type = string
7474
}

environments/skeleton/{{cookiecutter.environment}}/terraform/variables.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,4 +135,5 @@ variable "root_volume_size" {
135135
variable "k3s_token" {
136136
description = "Random cryptographically secure string for K3s token"
137137
type = string
138+
default = "k3s_token_replace_me"
138139
}

0 commit comments

Comments
 (0)