Skip to content

Commit 93a0e3c

Browse files
authored
Merge branch 'main' into binding-profile
2 parents 9f561fd + 193a5be commit 93a0e3c

File tree

24 files changed

+127
-96
lines changed

24 files changed

+127
-96
lines changed

ansible/bootstrap.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -313,10 +313,11 @@
313313
- include_role:
314314
name: azimuth_cloud.image_utils.linux_ansible_init
315315

316-
- hosts: k3s
316+
- hosts: k3s:&builder
317317
become: yes
318318
tags: k3s
319319
tasks:
320-
- ansible.builtin.include_role:
320+
- name: Install k3s
321+
ansible.builtin.include_role:
321322
name: k3s
322323
tasks_from: install.yml

ansible/extras.yml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,23 @@
1+
- hosts: k3s_server:!builder
2+
become: yes
3+
tags: k3s
4+
tasks:
5+
- name: Start k3s server
6+
ansible.builtin.include_role:
7+
name: k3s
8+
tasks_from: server-runtime.yml
9+
10+
# technically should be part of bootstrap.yml but hangs waiting on failed mounts
11+
# if runs before filesystems.yml after the control node has been reimaged
12+
- hosts: k3s_agent:!builder
13+
become: yes
14+
tags: k3s
15+
tasks:
16+
- name: Start k3s agents
17+
ansible.builtin.include_role:
18+
name: k3s
19+
tasks_from: agent-runtime.yml
20+
121
- hosts: basic_users:!builder
222
become: yes
323
tags:

ansible/roles/k3s/defaults/main.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,6 @@ k3s_version: "v1.31.0+k3s1"
33
k3s_selinux_release: v1.6.latest.1
44
k3s_selinux_rpm_version: 1.6-1
55
k3s_helm_version: v3.11.0
6+
k3s_bootstrap_token: '' # matches common environment default
7+
k3s_bootstrap_token_expiry: 10m
8+
k3s_server_name: "{{ None }}" # ansible managed

ansible/roles/k3s/files/start_k3s.yml

Lines changed: 0 additions & 44 deletions
This file was deleted.
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
---
2+
3+
- name: Template k3s agent env file
4+
when: k3s_bootstrap_token != ''
5+
ansible.builtin.template:
6+
dest: /etc/systemd/system/k3s-agent.service.env
7+
src: k3s-agent.service.env.j2
8+
owner: root
9+
group: root
10+
mode: 0640
11+
register: _k3s_agent_token_result
12+
13+
- name: Ensure password directory exists
14+
ansible.builtin.file:
15+
path: "/etc/rancher/node"
16+
state: directory
17+
owner: root
18+
group: root
19+
mode: 0640
20+
21+
- name: Write node password
22+
ansible.builtin.copy:
23+
dest: /etc/rancher/node/password
24+
content: "{{ vault_k3s_node_password }}"
25+
owner: root
26+
group: root
27+
mode: 0640 # normal k3s install is 644 but that doesn't feel right
28+
29+
- name: Start/restart k3s agent
30+
when: _k3s_agent_token_result.changed
31+
ansible.builtin.systemd:
32+
name: k3s-agent
33+
daemon_reload: true
34+
state: restarted
35+
enabled: true

ansible/roles/k3s/tasks/install.yml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,3 @@
7171
ansible.builtin.lineinfile:
7272
path: /etc/environment
7373
line: "KUBECONFIG=/etc/rancher/k3s/k3s.yaml"
74-
75-
- name: Install ansible-init playbook for k3s agent or server activation
76-
copy:
77-
src: start_k3s.yml
78-
dest: /etc/ansible-init/playbooks/0-start-k3s.yml
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
---
2+
3+
- name: Template k3s env file
4+
ansible.builtin.template:
5+
dest: /etc/systemd/system/k3s.service.env
6+
src: k3s.service.env.j2
7+
register: _k3s_env_file_status
8+
9+
- name: Start k3s server
10+
ansible.builtin.systemd:
11+
name: k3s
12+
daemon_reload: "{{ _k3s_env_file_status.changed }}"
13+
state: started
14+
enabled: true
15+
16+
# Possible race here as there is a delay between agents disconnecting and being registered as down, probably won't be hit in general use though
17+
- name: Check which k3s agents are connected
18+
ansible.builtin.shell:
19+
cmd: kubectl get nodes --no-headers | grep -w Ready
20+
register: _k3s_connected_nodes
21+
retries: 6 # task may fail if server is not ready yet
22+
delay: 10
23+
until: not _k3s_connected_nodes.failed
24+
25+
- when: _k3s_connected_nodes.stdout_lines | length != groups['k3s'] | length
26+
block:
27+
- name: Generate new bootstrap token if not all agents are connected
28+
no_log: true
29+
shell:
30+
cmd: "k3s token create --ttl {{ k3s_bootstrap_token_expiry }}"
31+
register: _k3s_token_output
32+
33+
- name: Set bootstrap token as fact
34+
set_fact:
35+
k3s_bootstrap_token: "{{ _k3s_token_output.stdout }}"
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
K3S_NODE_IP={{ ansible_host }}
2+
K3S_TOKEN={{ k3s_bootstrap_token }}
3+
K3S_URL=https://{{ k3s_server_name }}:6443
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
K3S_NODE_IP={{ ansible_host }}

ansible/roles/passwords/defaults/main.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ slurm_appliance_secrets:
88
vault_openhpc_mungekey: "{{ secrets_openhpc_mungekey | default(vault_openhpc_mungekey | default(secrets_openhpc_mungekey_default)) }}"
99
vault_freeipa_ds_password: "{{ vault_freeipa_ds_password | default(lookup('password', '/dev/null')) }}"
1010
vault_freeipa_admin_password: "{{ vault_freeipa_admin_password | default(lookup('password', '/dev/null')) }}"
11-
vault_k3s_token: "{{ vault_k3s_token | default(lookup('ansible.builtin.password', '/dev/null', length=64)) }}"
11+
vault_k3s_node_password: "{{ vault_k3s_node_password | default(lookup('ansible.builtin.password', '/dev/null', length=64)) }}"
1212
vault_pulp_admin_password: "{{ vault_pulp_admin_password | default(lookup('password', '/dev/null', chars=['ascii_letters', 'digits'])) }}"
1313
vault_demo_user_password: "{{ vault_demo_user_password | default(lookup('password', '/dev/null')) }}"
1414

0 commit comments

Comments
 (0)