|
41 | 41 | }) }} |
42 | 42 | changed_when: true |
43 | 43 |
|
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 | | -
|
66 | 44 | - name: Setup optional config file |
67 | 45 | when: agent_config_yaml is defined |
68 | 46 | block: |
|
103 | 81 | with_items: |
104 | 82 | - "K3S_TOKEN={{ token }}" |
105 | 83 |
|
106 | | -- name: Copy K3s service file |
| 84 | +- name: Modify ExecStart in k3s-agent.service to include API endpoint and extra args |
107 | 85 | 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 }} |
114 | 94 |
|
115 | | -- name: Enable and check K3s service |
| 95 | +- name: Enable and check K3s agent service |
116 | 96 | ansible.builtin.systemd: |
117 | 97 | name: k3s-agent |
118 | 98 | daemon_reload: "{{ true if k3s_agent_service.changed else false }}" |
|
0 commit comments