From f6f13c7f7abb55271288427581564026dcfcb51e Mon Sep 17 00:00:00 2001 From: Guilherme Maluf Balzana Date: Wed, 22 Jan 2020 16:11:12 +0000 Subject: [PATCH] Add binary install directory (#137) Binaries are currently droped in /usr/local/bin This commit add `node_exporter_binary_install_dir` variable where user can change the binary destination to `/opt/bin` for example. --- tasks/install.yml | 11 +++++++++-- tasks/preflight.yml | 4 ++-- templates/node_exporter.service.j2 | 2 +- vars/main.yml | 2 ++ 4 files changed, 14 insertions(+), 5 deletions(-) diff --git a/tasks/install.yml b/tasks/install.yml index 7d48a6b..47a54b0 100644 --- a/tasks/install.yml +++ b/tasks/install.yml @@ -1,4 +1,11 @@ --- +- name: create node_exporter binary install directory + file: + path: "{{ _node_exporter_binary_install_dir }}" + state: directory + owner: root + group: root + - name: Create the node_exporter group group: name: "{{ node_exporter_system_group }}" @@ -43,7 +50,7 @@ - name: Propagate node_exporter binaries copy: src: "/tmp/node_exporter-{{ node_exporter_version }}.linux-{{ go_arch }}/node_exporter" - dest: "/usr/local/bin/node_exporter" + dest: "{{ _node_exporter_binary_install_dir }}/node_exporter" mode: 0755 owner: root group: root @@ -54,7 +61,7 @@ - name: propagate locally distributed node_exporter binary copy: src: "{{ node_exporter_binary_local_dir }}/node_exporter" - dest: "/usr/local/bin/node_exporter" + dest: "{{ _node_exporter_binary_install_dir }}/node_exporter" mode: 0755 owner: root group: root diff --git a/tasks/preflight.yml b/tasks/preflight.yml index 5f44b01..9dedc0d 100644 --- a/tasks/preflight.yml +++ b/tasks/preflight.yml @@ -29,14 +29,14 @@ - name: Check if node_exporter is installed stat: - path: "/usr/local/bin/node_exporter" + path: "{{ _node_exporter_binary_install_dir }}/node_exporter" register: __node_exporter_is_installed check_mode: false tags: - node_exporter_install - name: Gather currently installed node_exporter version (if any) - command: "/usr/local/bin/node_exporter --version" + command: "{{ _node_exporter_binary_install_dir }}/node_exporter --version" args: warn: false changed_when: false diff --git a/templates/node_exporter.service.j2 b/templates/node_exporter.service.j2 index 8be2773..7773c3f 100644 --- a/templates/node_exporter.service.j2 +++ b/templates/node_exporter.service.j2 @@ -9,7 +9,7 @@ StartLimitInterval=0 Type=simple User={{ node_exporter_system_user }} Group={{ node_exporter_system_group }} -ExecStart=/usr/local/bin/node_exporter \ +ExecStart={{ _node_exporter_binary_install_dir }}/node_exporter \ {% for collector in node_exporter_enabled_collectors -%} {% if not collector is mapping %} --collector.{{ collector }} \ diff --git a/vars/main.yml b/vars/main.yml index fdcd126..945db28 100644 --- a/vars/main.yml +++ b/vars/main.yml @@ -7,3 +7,5 @@ go_arch_map: armv6l: 'armv6' go_arch: "{{ go_arch_map[ansible_architecture] | default(ansible_architecture) }}" + +_node_exporter_binary_install_dir: "/usr/local/bin"