Skip to content

Commit 8ab3706

Browse files
committed
Remove agent jinja template
Signed-off-by: Derek Nola <derek.nola@suse.com>
1 parent 85d0a42 commit 8ab3706

2 files changed

Lines changed: 10 additions & 59 deletions

File tree

roles/k3s_agent/tasks/main.yml

Lines changed: 10 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -41,28 +41,6 @@
4141
}) }}
4242
changed_when: true
4343

44-
- name: Compute final agent arguments
45-
ansible.builtin.set_fact:
46-
_api_endpoint_in_agent_config: >-
47-
{% if agent_config_yaml is defined and api_endpoint is defined and agent_config_yaml | regex_search('tls-san:.*' + api_endpoint | regex_escape(), ignorecase=True) %}
48-
true
49-
{% else %}
50-
false
51-
{% endif %}
52-
_api_endpoint_in_agent_args: >-
53-
{% if api_endpoint is defined and extra_agent_args | regex_search('--tls-san[=\s]+' + api_endpoint | regex_escape(), ignorecase=True) %}
54-
true
55-
{% else %}
56-
false
57-
{% endif %}
58-
59-
- name: Add TLS SAN to agent arguments if needed
60-
ansible.builtin.set_fact:
61-
opt_tls_san: >-
62-
{% if api_endpoint is defined and api_endpoint != ansible_hostname and _api_endpoint_in_agent_config | bool == false and _api_endpoint_in_agent_args | bool == false %}
63-
--tls-san={{ api_endpoint }}
64-
{% endif %}
65-
6644
- name: Setup optional config file
6745
when: agent_config_yaml is defined
6846
block:
@@ -103,16 +81,18 @@
10381
with_items:
10482
- "K3S_TOKEN={{ token }}"
10583

106-
- name: Copy K3s service file
84+
- name: Modify ExecStart in k3s-agent.service to include API endpoint and extra args
10785
register: k3s_agent_service
108-
ansible.builtin.template:
109-
src: "k3s-agent.service.j2"
110-
dest: "{{ systemd_dir }}/k3s-agent.service"
111-
owner: root
112-
group: root
113-
mode: "u=rw,g=r,o=r"
86+
ansible.builtin.replace:
87+
path: "{{ systemd_dir }}/k3s-agent.service"
88+
regexp: '^ExecStart=\/usr\/local\/bin\/k3s \\\n\s*agent.*'
89+
replace: |
90+
ExecStart=/usr/local/bin/k3s \
91+
agent \
92+
--server https://{{ api_endpoint }}:{{ api_port }} \
93+
{{ extra_agent_args }}
11494
115-
- name: Enable and check K3s service
95+
- name: Enable and check K3s agent service
11696
ansible.builtin.systemd:
11797
name: k3s-agent
11898
daemon_reload: "{{ true if k3s_agent_service.changed else false }}"

roles/k3s_agent/templates/k3s-agent.service.j2

Lines changed: 0 additions & 29 deletions
This file was deleted.

0 commit comments

Comments
 (0)