Skip to content

Commit

Permalink
allow setting options properly
Browse files Browse the repository at this point in the history
  • Loading branch information
bluppfisk committed Jul 25, 2023
1 parent a4e2360 commit 83672da
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 8 deletions.
11 changes: 8 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -45,7 +50,7 @@ None.

- hosts: all
roles:
- role: ansible-role-windows_exporter
- role: danielweeber.windows_exporter

## License

Expand Down
5 changes: 4 additions & 1 deletion defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
24 changes: 20 additions & 4 deletions tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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"
Expand Down

0 comments on commit 83672da

Please sign in to comment.