Skip to content

Commit 8e1b8ad

Browse files
committed
Add Remote Download for _common and node_exporter
Signed-off-by: c1rc0le <florian@sanys.fr>
1 parent 4bafa05 commit 8e1b8ad

6 files changed

Lines changed: 28 additions & 2 deletions

File tree

roles/_common/meta/argument_specs.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,12 @@ argument_specs:
6969
_common_system_group:
7070
description: "User group for the system user."
7171
default: ""
72+
_common_remote_download:
73+
description: Determines if the package archive is downloaded and extracted on local (false) or remote host (true)"
74+
default: "false"
75+
_common_remote_cache_path:
76+
description: "Remote path to stash the archive and its extraction"
77+
default: ""
7278
preflight:
7379
short_description: "Internal only - common preflight tasks"
7480
description: "Internal only - selinux requirements"

roles/_common/tasks/install.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,11 @@
5454
- download
5555
- "{{ ansible_parent_role_names | first | regex_replace(ansible_collection_name ~ '.', '') }}_download"
5656
become: false
57-
delegate_to: localhost
57+
delegate_to: "{{ inventory_hostname if (_common_remote_download | bool) else 'localhost' }}"
5858
block:
5959
- name: "Create localhost binary cache path"
6060
ansible.builtin.file:
61-
path: "{{ _common_local_cache_path }}"
61+
path: "{{ _common_remote_cache_path if (_common_remote_download | bool) else _common_local_cache_path }}"
6262
state: directory
6363
mode: 0755
6464
check_mode: false
@@ -115,6 +115,7 @@
115115
ansible.builtin.unarchive:
116116
src: "{{ _common_local_cache_path }}/{{ __common_binary_basename }}"
117117
dest: "{{ _common_local_cache_path }}"
118+
remote_src: "{{ _common_remote_download | bool }}"
118119
mode: 0755
119120
list_files: true
120121
extra_opts: "{{ _common_binary_unarchive_opts | default(omit, true) }}"
@@ -148,6 +149,7 @@
148149
ansible.builtin.copy:
149150
src: "{{ _common_local_cache_path }}/{{ item }}"
150151
dest: "{{ _common_binary_install_dir }}/{{ item }}"
152+
remote_src: "{{ _common_remote_download | bool }}"
151153
mode: 0755
152154
owner: root
153155
group: root

roles/_common/vars/main.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ _common_tls_server_config: {}
1919
_common_http_server_config: {}
2020
_common_basic_auth_users: {}
2121
_common_web_listen_address: ""
22+
_common_remote_download: "false"
23+
_common_remote_cache_path: ""
2224
# Variables that should not be overwritten
2325
__common_binary_basename: "{{ _common_binary_url | urlsplit('path') | basename }}"
2426
__common_github_api_headers: "{{ {'GITHUB_TOKEN': lookup('ansible.builtin.env', 'GITHUB_TOKEN')} if (lookup('ansible.builtin.env', 'GITHUB_TOKEN')) else {} }}"

roles/node_exporter/defaults/main.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,11 @@ node_exporter_system_user: "{{ node_exporter_system_group }}"
3333
node_exporter_config_dir: "/etc/node_exporter"
3434
# Local path to stash the archive and its extraction
3535
node_exporter_local_cache_path: "/tmp/node_exporter-{{ ansible_facts['system'] | lower }}-{{ _node_exporter_go_ansible_arch }}/{{ node_exporter_version }}"
36+
37+
# If false (the default) we download node exporter archive and unpack it on localhost, before
38+
# uploading it to the remote host(s). If true we download and unpack the archive on the remote
39+
# host directly.
40+
node_exporter_remote_download: false
41+
42+
# Remote path to stash the archive and its extraction
43+
node_exporter_remote_cache_path: "/tmp/node_exporter-{{ ansible_facts['system'] | lower }}-{{ _node_exporter_go_ansible_arch }}/{{ node_exporter_version }}"

roles/node_exporter/meta/argument_specs.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,3 +82,9 @@ argument_specs:
8282
node_exporter_config_dir:
8383
description: "Path to directory with node_exporter configuration"
8484
default: "/etc/node_exporter"
85+
node_exporter_remote_download:
86+
description: "Determines if the node exporter package archive is downloaded and extracted on local (false) or remote host (true)"
87+
default: false
88+
node_exporter_remote_cache_path:
89+
description: "Remote path to stash the archive and its extraction"
90+
default: "/tmp/node_exporter-{{ ansible_facts['system'] | lower }}-{{ _node_exporter_go_ansible_arch }}/{{ node_exporter_version }}"

roles/node_exporter/tasks/main.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
_common_system_user: "{{ node_exporter_system_user }}"
2222
_common_config_dir: "{{ node_exporter_config_dir }}"
2323
_common_binary_unarchive_opts: ['--strip-components=1']
24+
_common_remote_download: "{{ node_exporter_remote_download }}"
25+
_common_remote_cache_path: "{{ node_exporter_remote_cache_path }}"
2426
tags:
2527
- node_exporter_install
2628

0 commit comments

Comments
 (0)