Skip to content

Commit 35b89fc

Browse files
author
Alexander Temp
committed
fix(agent): separate download and upload paths for agent package transfer
Fixes #741 The `win_copy` and `copy` modules always expect their source file to be located either on the Ansible controller, or on the target host itself when `remote_src: true` is set. They cannot transparently bridge a file between two different remote hosts. Previously, a single path variable (`__checkmk_agent_agent.file.*`) was used both as the destination for the initial package download (which may run on a delegated host, e.g. `localhost`, depending on `checkmk_agent_delegate_download`) and as the source/destination for the subsequent copy task onto the actual target host. When the download was delegated to a host different from the target, this caused the copy task to fail, since the file did not exist at the expected location on the target. This change splits the previously shared path into two explicit, independent path sets: - `__checkmk_agent_agent.file.download.*`: where the package is downloaded to (on the delegated/download host). - `__checkmk_agent_agent.file.upload.*`: where the package is copied/uploaded to on the target host, and subsequently installed from. All download tasks (`get_url`/`win_get_url` via `checkmk_agent_delegate_download`) now write to `file.download.*`, while the `copy`/`win_copy` tasks explicitly use `file.download.*` as `src` and `file.upload.*` as `dest`. Installation tasks (`package`, `zypper`, `win_package`) now consistently reference `file.upload.*`, since that is the final location on the target host. Additionally: - `checkmk_agent_delegate_download` is changed from a hostname-based variable (defaulting to `inventory_hostname`) to a boolean, making the delegation intent explicit rather than implicit through hostname comparison. - `__checkmk_agent_host_tmp_dir` (used for the download destination) is now defined centrally in `vars/main.yml`, while OS-specific `__checkmk_agent_lin_tmp_dir` / `__checkmk_agent_win_tmp_dir` variables are introduced for the upload destination on Linux and Windows targets respectively. Signed-off-by: Alexander Temp <alexander.temp@sit.nrw>
1 parent d85114d commit 35b89fc

13 files changed

Lines changed: 81 additions & 57 deletions

File tree

roles/agent/defaults/main.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ checkmk_agent_configure_firewall: true
4949

5050
## Delegation
5151
checkmk_agent_delegate_api_calls: 'localhost'
52-
checkmk_agent_delegate_download: "{{ inventory_hostname }}"
52+
checkmk_agent_delegate_download: true
5353
checkmk_agent_delegate_registration: false
5454
checkmk_agent_delegate_registration_target: "{{ inventory_hostname }}"
5555

roles/agent/tasks/Debian.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
- name: "{{ ansible_facts['os_family'] }} Derivatives: Install host-specific {{ checkmk_agent_edition | upper }} Agent."
33
become: true
44
ansible.builtin.package:
5-
deb: "{{ __checkmk_agent_agent.file.host }}"
5+
deb: "{{ __checkmk_agent_agent.file.upload.host }}"
66
force: "{{ checkmk_agent_force_install | bool }}"
77
state: present
88
when: |
@@ -14,7 +14,7 @@
1414
- name: "{{ ansible_facts['os_family'] }} Derivatives: Install folder-specific {{ checkmk_agent_edition | upper }} Agent."
1515
become: true
1616
ansible.builtin.package:
17-
deb: "{{ __checkmk_agent_agent.file.pro }}"
17+
deb: "{{ __checkmk_agent_agent.file.upload.pro }}"
1818
force: "{{ checkmk_agent_force_install | bool }}"
1919
state: present
2020
when: |
@@ -26,7 +26,7 @@
2626
- name: "{{ ansible_facts['os_family'] }} Derivatives: Install Vanilla Agent."
2727
become: true
2828
ansible.builtin.package:
29-
deb: "{{ __checkmk_agent_agent.file.community }}"
29+
deb: "{{ __checkmk_agent_agent.file.upload.community }}"
3030
force: "{{ checkmk_agent_force_install | bool }}"
3131
state: present
3232
when: |

roles/agent/tasks/Linux-files.yml

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
os_type={{ __checkmk_agent_files_mapping[ansible_facts['os_family']] }}&\
88
agent_type=host_name"
99
validate_certs: "{{ checkmk_agent_server_validate_certs | bool }}"
10-
dest: "{{ __checkmk_agent_agent.file.host }}"
10+
dest: "{{ __checkmk_agent_agent.file.download.host }}"
1111
method: GET
1212
headers:
1313
Authorization: "Bearer {{ checkmk_agent_user }} {{ __checkmk_agent_auth }}"
@@ -20,7 +20,7 @@
2020
# This task may fail, as we fall back to the vanilla agent later
2121
failed_when: false
2222
changed_when: __checkmk_agent_host_download_state.status is defined and __checkmk_agent_host_download_state.status == 200
23-
delegate_to: "{{ checkmk_agent_delegate_download }}"
23+
delegate_to: "{{ 'localhost' if checkmk_agent_delegate_download else 'inventory_hostname' }}"
2424
tags:
2525
- download-package
2626

@@ -39,7 +39,7 @@
3939
folder_name={{ checkmk_agent_folder }}&\
4040
agent_type=generic"
4141
validate_certs: "{{ checkmk_agent_server_validate_certs | bool }}"
42-
dest: "{{ __checkmk_agent_agent.file.pro }}"
42+
dest: "{{ __checkmk_agent_agent.file.download.pro }}"
4343
method: GET
4444
headers:
4545
Authorization: "Bearer {{ checkmk_agent_user }} {{ __checkmk_agent_auth }}"
@@ -56,7 +56,7 @@
5656
# This task may fail, as we fall back to the vanilla agent later
5757
failed_when: false
5858
changed_when: __checkmk_agent_folder_download_state.status is defined and __checkmk_agent_folder_download_state.status == 200
59-
delegate_to: "{{ checkmk_agent_delegate_download }}"
59+
delegate_to: "{{ 'localhost' if checkmk_agent_delegate_download else 'inventory_hostname' }}"
6060
tags:
6161
- download-package
6262

@@ -71,7 +71,7 @@
7171
ansible.builtin.get_url: # This has to be the `get_url` module, as the download works different than for the bakery-based tasks.
7272
url: "{{ __checkmk_agent_agent.url.community }}"
7373
validate_certs: "{{ checkmk_agent_server_validate_certs | bool }}"
74-
dest: "{{ __checkmk_agent_agent.file.community }}"
74+
dest: "{{ __checkmk_agent_agent.file.download.community }}"
7575
mode: '0644'
7676
timeout: "{{ checkmk_agent_download_timeout | default(omit) }}"
7777
become: false
@@ -82,14 +82,14 @@
8282
retries: 3
8383
delay: 10
8484
until: "not __checkmk_agent_vanilla_download_state.failed | bool"
85-
delegate_to: "{{ checkmk_agent_delegate_download }}"
85+
delegate_to: "{{ 'localhost' if checkmk_agent_delegate_download else 'inventory_hostname' }}"
8686
tags:
8787
- download-package
8888

8989
- name: "{{ ansible_facts['system'] }}: Transfer host-specific {{ checkmk_agent_edition | upper }} Agent."
9090
ansible.builtin.copy:
91-
src: "{{ __checkmk_agent_agent.file.host }}"
92-
dest: "{{ __checkmk_agent_agent.file.host }}"
91+
src: "{{ __checkmk_agent_agent.file.download.host }}"
92+
dest: "{{ __checkmk_agent_agent.file.upload.host }}"
9393
mode: "0644"
9494
when: |
9595
checkmk_agent_edition | lower != "community"
@@ -100,8 +100,8 @@
100100

101101
- name: "{{ ansible_facts['system'] }}: Transfer folder-specific {{ checkmk_agent_edition | upper }} Agent."
102102
ansible.builtin.copy:
103-
src: "{{ __checkmk_agent_agent.file.pro }}"
104-
dest: "{{ __checkmk_agent_agent.file.pro }}"
103+
src: "{{ __checkmk_agent_agent.file.download.pro }}"
104+
dest: "{{ __checkmk_agent_agent.file.upload.pro }}"
105105
mode: "0644"
106106
when: |
107107
checkmk_agent_edition | lower != "community"
@@ -112,8 +112,8 @@
112112

113113
- name: "{{ ansible_facts['system'] }}: Transfer Vanilla {{ checkmk_agent_edition | upper }} Agent."
114114
ansible.builtin.copy:
115-
src: "{{ __checkmk_agent_agent.file.community }}"
116-
dest: "{{ __checkmk_agent_agent.file.community }}"
115+
src: "{{ __checkmk_agent_agent.file.download.community }}"
116+
dest: "{{ __checkmk_agent_agent.file.upload.community }}"
117117
mode: "0644"
118118
when: |
119119
checkmk_agent_delegate_download != inventory_hostname

roles/agent/tasks/Linux.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,6 @@
282282
loop:
283283
- "{{ __checkmk_agent_agent.file.community }}"
284284
- "{{ __checkmk_agent_agent.file.pro }}"
285-
- "{{ __checkmk_agent_agent.file.host }}"
285+
- "{{ __checkmk_agent_agent.file.download.host }}"
286286
tags:
287287
- download-package

roles/agent/tasks/RedHat.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
- name: "{{ ansible_facts['os_family'] }} Derivatives: Install host-specific {{ checkmk_agent_edition | upper }} Agent."
33
become: true
44
ansible.builtin.package:
5-
name: "{{ __checkmk_agent_agent.file.host }}"
5+
name: "{{ __checkmk_agent_agent.file.upload.host }}"
66
state: present
77
disable_gpg_check: true
88
when: |
@@ -14,7 +14,7 @@
1414
- name: "{{ ansible_facts['os_family'] }} Derivatives: Install folder-specific {{ checkmk_agent_edition | upper }} Agent."
1515
become: true
1616
ansible.builtin.package:
17-
name: "{{ __checkmk_agent_agent.file.pro }}"
17+
name: "{{ __checkmk_agent_agent.file.upload.pro }}"
1818
state: present
1919
disable_gpg_check: true
2020
when: |
@@ -26,7 +26,7 @@
2626
- name: "{{ ansible_facts['os_family'] }} Derivatives: Install Vanilla Agent."
2727
become: true
2828
ansible.builtin.package:
29-
name: "{{ __checkmk_agent_agent.file.community }}"
29+
name: "{{ __checkmk_agent_agent.file.upload.community }}"
3030
state: present
3131
disable_gpg_check: true
3232
when: |

roles/agent/tasks/Suse.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
- name: "{{ ansible_facts['os_family'] }} Derivatives: Install host-specific {{ checkmk_agent_edition | upper }} Agent."
33
become: true
44
community.general.zypper:
5-
name: "{{ __checkmk_agent_agent.file.host }}"
5+
name: "{{ __checkmk_agent_agent.file.upload.host }}"
66
force: "{{ checkmk_agent_force_install | bool }}"
77
state: present
88
disable_gpg_check: true
@@ -15,7 +15,7 @@
1515
- name: "{{ ansible_facts['os_family'] }} Derivatives: Install folder-specific {{ checkmk_agent_edition | upper }} Agent."
1616
become: true
1717
community.general.zypper:
18-
name: "{{ __checkmk_agent_agent.file.pro }}"
18+
name: "{{ __checkmk_agent_agent.file.upload.pro }}"
1919
force: "{{ checkmk_agent_force_install | bool }}"
2020
state: present
2121
disable_gpg_check: true
@@ -28,7 +28,7 @@
2828
- name: "{{ ansible_facts['os_family'] }} Derivatives: Install Vanilla Agent."
2929
become: true
3030
community.general.zypper:
31-
name: "{{ __checkmk_agent_agent.file.community }}"
31+
name: "{{ __checkmk_agent_agent.file.upload.community }}"
3232
force: "{{ checkmk_agent_force_install | bool }}"
3333
state: present
3434
disable_gpg_check: true

roles/agent/tasks/Win32NT-files.yml

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
os_type={{ __checkmk_agent_files_mapping[ansible_facts['os_family']] }}&\
88
agent_type=host_name"
99
validate_certs: "{{ checkmk_agent_server_validate_certs | bool }}"
10-
dest: "{{ __checkmk_agent_agent.file.host }}"
10+
dest: "{{ __checkmk_agent_agent.file.download.host }}"
1111
method: GET
1212
headers:
1313
Authorization: "Bearer {{ checkmk_agent_user }} {{ __checkmk_agent_auth }}"
@@ -20,7 +20,7 @@
2020
# This task may fail, as we fall back to the vanilla agent later
2121
failed_when: false
2222
changed_when: __checkmk_agent_host_download_state.status_code is defined and __checkmk_agent_host_download_state.status_code == 200
23-
delegate_to: "{{ checkmk_agent_delegate_download }}"
23+
delegate_to: "{{ 'localhost' if checkmk_agent_delegate_download else 'inventory_hostname' }}"
2424
tags:
2525
- download-package
2626

@@ -39,7 +39,7 @@
3939
folder_name={{ checkmk_agent_folder }}&\
4040
agent_type=generic"
4141
validate_certs: "{{ checkmk_agent_server_validate_certs | bool }}"
42-
dest: "{{ __checkmk_agent_agent.file.pro }}"
42+
dest: "{{ __checkmk_agent_agent.file.download.pro }}"
4343
method: GET
4444
headers:
4545
Authorization: "Bearer {{ checkmk_agent_user }} {{ __checkmk_agent_auth }}"
@@ -56,7 +56,7 @@
5656
# This task may fail, as we fall back to the vanilla agent later
5757
failed_when: false
5858
changed_when: __checkmk_agent_folder_download_state.status_code is defined and __checkmk_agent_folder_download_state.status_code == 200
59-
delegate_to: "{{ checkmk_agent_delegate_download }}"
59+
delegate_to: "{{ 'localhost' if checkmk_agent_delegate_download else 'inventory_hostname' }}"
6060
tags:
6161
- download-package
6262

@@ -71,7 +71,7 @@
7171
ansible.windows.win_get_url:
7272
url: "{{ __checkmk_agent_agent.url.community }}"
7373
validate_certs: "{{ checkmk_agent_server_validate_certs | bool }}"
74-
dest: "{{ __checkmk_agent_agent.file.community }}"
74+
dest: "{{ __checkmk_agent_agent.file.download.community }}"
7575
timeout: "{{ checkmk_agent_download_timeout | default(omit) }}"
7676
when: |
7777
checkmk_agent_edition | lower == "community"
@@ -80,14 +80,14 @@
8080
retries: 3
8181
delay: 10
8282
until: "not __checkmk_agent_vanilla_download_state.failed | bool"
83-
delegate_to: "{{ checkmk_agent_delegate_download }}"
83+
delegate_to: "{{ 'localhost' if checkmk_agent_delegate_download else 'inventory_hostname' }}"
8484
tags:
8585
- download-package
8686

8787
- name: "{{ ansible_facts['system'] }}: Transfer host-specific {{ checkmk_agent_edition | upper }} Agent."
8888
ansible.windows.win_copy:
89-
src: "{{ __checkmk_agent_agent.file.host }}"
90-
dest: "{{ __checkmk_agent_agent.file.host }}"
89+
src: "{{ __checkmk_agent_agent.file.download.host }}"
90+
dest: "{{ __checkmk_agent_agent.file.upload.host }}"
9191
when: |
9292
checkmk_agent_edition | lower != "community"
9393
and checkmk_agent_host_specific | bool
@@ -97,8 +97,8 @@
9797

9898
- name: "{{ ansible_facts['system'] }}: Transfer folder-specific {{ checkmk_agent_edition | upper }} Agent."
9999
ansible.windows.win_copy:
100-
src: "{{ __checkmk_agent_agent.file.pro }}"
101-
dest: "{{ __checkmk_agent_agent.file.pro }}"
100+
src: "{{ __checkmk_agent_agent.file.download.pro }}"
101+
dest: "{{ __checkmk_agent_agent.file.upload.pro }}"
102102
when: |
103103
checkmk_agent_edition | lower != "community"
104104
and checkmk_agent_folder_specific | bool
@@ -108,8 +108,8 @@
108108

109109
- name: "{{ ansible_facts['system'] }}: Transfer Vanilla {{ checkmk_agent_edition | upper }} Agent."
110110
ansible.windows.win_copy:
111-
src: "{{ __checkmk_agent_agent.file.community }}"
112-
dest: "{{ __checkmk_agent_agent.file.community }}"
111+
src: "{{ __checkmk_agent_agent.file.download.community }}"
112+
dest: "{{ __checkmk_agent_agent.file.upload.community }}"
113113
when: |
114114
checkmk_agent_delegate_download != inventory_hostname
115115
and (checkmk_agent_edition | lower == "community"

roles/agent/tasks/Windows.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
- name: "{{ ansible_facts['os_family'] }}: Install host-specific {{ checkmk_agent_edition | upper }} Agent."
33
ansible.windows.win_package:
4-
path: "{{ __checkmk_agent_agent.file.host }}"
4+
path: "{{ __checkmk_agent_agent.file.upload.host }}"
55
state: present
66
when: |
77
checkmk_agent_edition | lower != "community"
@@ -11,7 +11,7 @@
1111

1212
- name: "{{ ansible_facts['os_family'] }}: Install folder-specific {{ checkmk_agent_edition | upper }} Agent."
1313
ansible.windows.win_package:
14-
path: "{{ __checkmk_agent_agent.file.pro }}"
14+
path: "{{ __checkmk_agent_agent.file.upload.pro }}"
1515
state: present
1616
when: |
1717
checkmk_agent_edition | lower != "community"
@@ -21,7 +21,7 @@
2121

2222
- name: "{{ ansible_facts['os_family'] }}: Install Vanilla Agent."
2323
ansible.windows.win_package:
24-
path: "{{ __checkmk_agent_agent.file.community }}"
24+
path: "{{ __checkmk_agent_agent.file.upload.community }}"
2525
state: present
2626
when: |
2727
checkmk_agent_edition | lower == "community"
@@ -34,8 +34,8 @@
3434
path: "{{ item }}"
3535
state: absent
3636
loop:
37-
- "{{ __checkmk_agent_agent.file.community }}"
38-
- "{{ __checkmk_agent_agent.file.pro }}"
39-
- "{{ __checkmk_agent_agent.file.host }}"
37+
- "{{ __checkmk_agent_agent.file.upload.community }}"
38+
- "{{ __checkmk_agent_agent.file.upload.pro }}"
39+
- "{{ __checkmk_agent_agent.file.upload.host }}"
4040
tags:
4141
- download-package

roles/agent/vars/Debian.yml

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
11
---
2-
__checkmk_agent_host_tmp_dir: "/tmp"
2+
__checkmk_agent_lin_tmp_dir: "/tmp"
33

44
__checkmk_agent_agent:
55
url:
66
community: "{{ __checkmk_agent_site_url }}/check_mk/agents/check-mk-agent_{{ checkmk_agent_version }}-1_all.deb"
77
pro: "{{ __checkmk_agent_site_url }}/check_mk/api/1.0/domain-types/agent/actions/download_by_host/invoke"
88
file:
9-
community: "{{ __checkmk_agent_host_tmp_dir }}/check-mk-agent_{{ checkmk_agent_version }}-vanilla.deb"
10-
pro: "{{ __checkmk_agent_host_tmp_dir }}/check-mk-agent_{{ checkmk_agent_version }}-generic.deb"
11-
host: "{{ __checkmk_agent_host_tmp_dir }}/check-mk-agent_{{ checkmk_agent_version }}-{{ inventory_hostname }}.deb"
9+
download:
10+
community: "{{ __checkmk_agent_host_tmp_dir }}check-mk-agent_{{ checkmk_agent_version }}-vanilla.deb"
11+
pro: "{{ __checkmk_agent_host_tmp_dir }}check-mk-agent_{{ checkmk_agent_version }}-generic.deb"
12+
host: "{{ __checkmk_agent_host_tmp_dir }}check-mk-agent_{{ checkmk_agent_version }}-{{ inventory_hostname }}.deb"
13+
upload:
14+
community: "{{ __checkmk_agent_lin_tmp_dir }}/check-mk-agent_{{ checkmk_agent_version }}-vanilla.deb"
15+
pro: "{{ __checkmk_agent_lin_tmp_dir }}/check-mk-agent_{{ checkmk_agent_version }}-generic.deb"
16+
host: "{{ __checkmk_agent_lin_tmp_dir }}/check-mk-agent_{{ checkmk_agent_version }}-{{ inventory_hostname }}.deb"

roles/agent/vars/RedHat.yml

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
11
---
2-
__checkmk_agent_host_tmp_dir: "/tmp"
2+
__checkmk_agent_lin_tmp_dir: "/tmp"
33

44
__checkmk_agent_agent:
55
url:
66
community: "{{ __checkmk_agent_site_url }}/check_mk/agents/check-mk-agent-{{ checkmk_agent_version }}-1.noarch.rpm"
77
pro: "{{ __checkmk_agent_site_url }}/check_mk/api/1.0/domain-types/agent/actions/download_by_host/invoke"
88
file:
9-
community: "{{ __checkmk_agent_host_tmp_dir }}/check-mk-agent-{{ checkmk_agent_version }}-1.noarch-vanilla.rpm"
10-
pro: "{{ __checkmk_agent_host_tmp_dir }}/check-mk-agent-{{ checkmk_agent_version }}-1.noarch-generic.rpm"
11-
host: "{{ __checkmk_agent_host_tmp_dir }}/check-mk-agent-{{ checkmk_agent_version }}-1.noarch-{{ inventory_hostname }}.rpm"
9+
download:
10+
community: "{{ __checkmk_agent_host_tmp_dir }}check-mk-agent-{{ checkmk_agent_version }}-1.noarch-vanilla.rpm"
11+
pro: "{{ __checkmk_agent_host_tmp_dir }}check-mk-agent-{{ checkmk_agent_version }}-1.noarch-generic.rpm"
12+
host: "{{ __checkmk_agent_host_tmp_dir }}check-mk-agent-{{ checkmk_agent_version }}-1.noarch-{{ inventory_hostname }}.rpm"
13+
upload:
14+
community: "{{ __checkmk_agent_host_tmp_dir }}/check-mk-agent-{{ checkmk_agent_version }}-1.noarch-vanilla.rpm"
15+
pro: "{{ __checkmk_agent_host_tmp_dir }}/check-mk-agent-{{ checkmk_agent_version }}-1.noarch-generic.rpm"
16+
host: "{{ __checkmk_agent_host_tmp_dir }}/check-mk-agent-{{ checkmk_agent_version }}-1.noarch-{{ inventory_hostname }}.rpm"

0 commit comments

Comments
 (0)