Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature: allow downloading of package by remote host #499

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions roles/_common/tasks/install.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,12 @@
- install
- "{{ ansible_parent_role_names | first | regex_replace(ansible_collection_name ~ '.', '') }}_install"

- name: "Create localhost binary cache path"
- name: "Create binary cache path on {{ 'localhost' if (_common_delegate_to_localhost | bool) else 'remote host'}}"
ansible.builtin.file:
path: "{{ _common_local_cache_path }}"
state: directory
mode: 0755
delegate_to: localhost
delegate_to: "{{ 'localhost' if (_common_delegate_to_localhost | bool) else omit }}"
check_mode: false
become: false
tags:
Expand All @@ -78,7 +78,7 @@
run_once: true
when: (_common_checksums_url)

- name: "Download {{ __common_binary_basename }}"
- name: "Download {{ __common_binary_basename }} from {{ _common_binary_url }} on {{ 'localhost' if (_common_delegate_to_localhost | bool) else 'remote host'}}"
ansible.builtin.get_url:
url: "{{ _common_binary_url }}"
dest: "{{ _common_local_cache_path }}/{{ _common_binary_name | default(__common_binary_basename) }}"
Expand All @@ -90,17 +90,18 @@
retries: 5
delay: 2
# run_once: true # <-- this can't be set due to multi-arch support
delegate_to: localhost
delegate_to: "{{ 'localhost' if (_common_delegate_to_localhost | bool) else omit }}"
check_mode: false

- name: "Unpack binary archive {{ __common_binary_basename }}"
- name: "Unpack binary archive {{ __common_binary_basename }} on {{ 'localhost' if (_common_delegate_to_localhost | bool) else 'remote host'}}"
ansible.builtin.unarchive:
src: "{{ _common_local_cache_path }}/{{ __common_binary_basename }}"
dest: "{{ _common_local_cache_path }}"
mode: 0755
list_files: true
extra_opts: "{{ _common_binary_unarchive_opts | default(omit, true) }}"
delegate_to: localhost
remote_src: "{{ not (_common_delegate_to_localhost | bool) }}"
delegate_to: "{{ 'localhost' if (_common_delegate_to_localhost | bool) else omit }}"
check_mode: false
when: __common_binary_basename is search('\.zip$|\.tar\.gz$')

Expand Down Expand Up @@ -129,6 +130,7 @@
mode: 0755
owner: root
group: root
remote_src: "{{ not (_common_delegate_to_localhost | bool) }}"
loop: "{{ _common_binaries }}"
become: true
notify:
Expand Down
1 change: 1 addition & 0 deletions roles/_common/vars/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ _common_tls_server_config: {}
_common_http_server_config: {}
_common_basic_auth_users: {}
_common_web_listen_address: ""
_common_delegate_to_localhost: "true"
# Variables that should not be overwritten
__common_binary_basename: "{{ _common_binary_url | urlsplit('path') | basename }}"
__common_github_api_headers: "{{ {'GITHUB_TOKEN': lookup('ansible.builtin.env', 'GITHUB_TOKEN')} if (lookup('ansible.builtin.env', 'GITHUB_TOKEN')) else {} }}"
Expand Down
5 changes: 5 additions & 0 deletions roles/node_exporter/defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,8 @@ node_exporter_system_user: "{{ node_exporter_system_group }}"
node_exporter_config_dir: "/etc/node_exporter"
# Local path to stash the archive and its extraction
node_exporter_local_cache_path: "/tmp/node_exporter-{{ ansible_system | lower }}-{{ _node_exporter_go_ansible_arch }}/{{ node_exporter_version }}"
# If true (the default) we download node exporter archive and unpack it on localhost, before
# uploading it to the remote host(s). If false we download and unpack the archive on the remote
# host directly, which may be useful if the ansible controller host is slower (network-wise)
# than the remote host.
node_exporter_localhost_download: true
3 changes: 3 additions & 0 deletions roles/node_exporter/meta/argument_specs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -82,3 +82,6 @@ argument_specs:
node_exporter_config_dir:
description: "Path to directory with node_exporter configuration"
default: "/etc/node_exporter"
node_exporter_localhost_download:
description: "Determines if the node exporter package archive is downloaded and extracted on local (true) or remote host (false)"
default: true
1 change: 1 addition & 0 deletions roles/node_exporter/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
_common_system_user: "{{ node_exporter_system_user }}"
_common_config_dir: "{{ node_exporter_config_dir }}"
_common_binary_unarchive_opts: ['--strip-components=1']
_common_delegate_to_localhost: "{{ node_exporter_localhost_download }}"
tags:
- node_exporter_install

Expand Down
Loading