diff --git a/README.md b/README.md index 6890dc8..bafde08 100644 --- a/README.md +++ b/README.md @@ -24,13 +24,18 @@ If you change the version, the `windows_exporter` binary will be replaced with t windows_exporter_bin_path: 'C:\Windows\temp\windows_exporter-{{ windows_exporter_version }}-{{ windows_exporter_arch }}.msi' - The path where the `windows_exporter` binary will be downloaded and installed from. + windows_exporter_listen_address: '0.0.0.0' + windows_exporter_listen_port: 9182 + windows_exporter_textfile_dir: null + +Commonly used service options. + windows_exporter_options: '' Any additional options to pass to `windows_exporter` when it starts, e.g. `--no-collector.wifi` if you want to ignore any WiFi data. -Need to use MSI Parametes as stated in https://github.com/prometheus-community/windows_exporter#installation +Need to use MSI Parameters as stated in https://github.com/prometheus-community/windows_exporter#installation windows_exporter_state: started windows_exporter_start_mode: delayed @@ -45,7 +50,7 @@ None. - hosts: all roles: - - role: ansible-role-windows_exporter + - role: danielweeber.windows_exporter ## License diff --git a/defaults/main.yml b/defaults/main.yml index 0a57da3..63f5927 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -3,8 +3,11 @@ windows_exporter_version: '0.18.1' windows_exporter_arch: 'amd64' windows_exporter_download_url: https://github.com/prometheus-community/windows_exporter/releases/download/v{{ windows_exporter_version }}/windows_exporter-{{ windows_exporter_version }}-{{ windows_exporter_arch }}.msi -windows_exporter_options: '' +windows_exporter_options: [] windows_exporter_bin_path: '"C:\Program Files\windows_exporter\windows_exporter.exe"' windows_exporter_state: started windows_exporter_start_mode: delayed windows_exporter_allow_from: 'any' +windows_exporter_listen_address: '0.0.0.0' +windows_exporter_listen_port: 9182 +windows_exporter_textfile_dir: null diff --git a/tasks/main.yml b/tasks/main.yml index d414c48..93541a5 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -26,11 +26,27 @@ or not windows_exporter_installed_check.stat.exists register: windows_exporter_download_check +- name: create options string + tags: + test + block: + - name: list all options + set_fact: + windows_exporter_options: "{{ windows_exporter_options|default([]) + [item.key + '=' + item.value|string] if item.value is defined }}" + with_dict: + - LISTEN_ADDR: "{{ windows_exporter_listen_address }}" + - LISTEN_PORT: "{{ windows_exporter_listen_port }}" + - TEXTFILE_DIR: "{{ windows_exporter_textfile_dir }}" + + - name: concatenate options to parameter string + set_fact: + windows_exporter_options_string: "{{ ' '.join(windows_exporter_options) }}" + - name: install Windows exporter win_package: path: '{{ ansible_env.TEMP }}\windows_exporter_install.msi' state: present - arguments: "{{ windows_exporter_options }}" + arguments: "{{ windows_exporter_options_string }}" when: > windows_exporter_version_check.stderr is not defined or windows_exporter_version not in windows_exporter_version_check.stderr @@ -43,10 +59,10 @@ changed_when: false register: firewall_enabled -- name: Firewall rule to allow Prometheus to scrape on port 9182 TCP +- name: Firewall rule to allow Prometheus to scrape on port {{ windows_exporter_listen_port }} TCP win_firewall_rule: name: prometheus_exporter - localport: 9182 + localport: "{{ windows_exporter_listen_port }}" action: allow direction: in protocol: tcp @@ -63,7 +79,7 @@ - name: Verify windows_exporter is responding to requests. win_uri: - url: http://localhost:9182/ + url: http://localhost:{{ windows_exporter_listen_port }}/ return_content: true register: metrics_output failed_when: "'Metrics' not in metrics_output.content"