Skip to content

Commit

Permalink
fix: use startup script in windows task
Browse files Browse the repository at this point in the history
  • Loading branch information
antmelekhin committed Jul 1, 2023
1 parent 7d0198c commit e915e9e
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 18 deletions.
28 changes: 10 additions & 18 deletions tasks/Win32NT/configure.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@
value: '{{ postgres_exporter_data_source_name }}'
state: present

- name: 'Windows | Configure startup script for Postgres Exporter'
win_template:
src: 'Start-PostgresExporter.ps1.j2'
dest: '{{ postgres_exporter_install_path }}\Start-PostgresExporter.ps1'
register: _postgres_exporter_startup_script

- name: 'Windows | Configure web config file for Postgres Exporter'
win_template:
src: 'web_config.yaml.j2'
Expand All @@ -16,28 +22,13 @@
postgres_exporter_http_server_config | length or
postgres_exporter_basic_auth_users | length

- name: 'Windows | Set arguments'
ansible.builtin.set_fact:
_postgres_exporter_arguments: >-
--web.listen-address {{ postgres_exporter_web_listen_address }}:{{ postgres_exporter_web_listen_port }}
--web.telemetry-path {{ postgres_exporter_web_telemetry_path }}
{%- if postgres_exporter_tls_server_config | length or postgres_exporter_http_server_config | length or postgres_exporter_basic_auth_users | length %}
--web.config.file "{{ postgres_exporter_config_path }}\web_config.yaml"
{%- endif %}
{%- if postgres_exporter_disable_default_metrics | bool %} --disable-default-metrics {%- endif %}
{%- if postgres_exporter_disable_settings_metrics | bool %} --disable-settings-metrics {%- endif %}
{%- for collector in postgres_exporter_collectors %} --{{ collector }} {%- endfor %}
{%- if postgres_exporter_extend_query_path | length > 0 %} --extend.query-path {{ postgres_exporter_extend_query_path }} {%- endif %}
--log.level {{ postgres_exporter_log_level }}
--log.format {{ postgres_exporter_log_format }}
- name: 'Windows | Ensure scheduled task for Postgres Exporter is enabled at boot'
win_scheduled_task:
name: 'Postgres Exporter'
description: 'Prometheus exporter for Postgres server metrics.'
actions:
- path: '{{ postgres_exporter_install_path }}\postgres_exporter.exe'
arguments: '{{ _postgres_exporter_arguments }}'
- path: '%SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe'
arguments: '-ExecutionPolicy ByPass -File "{{ postgres_exporter_install_path }}\Start-PostgresExporter.ps1"'
triggers:
- type: 'boot'
execution_time_limit: 'PT0S'
Expand All @@ -50,7 +41,8 @@
win_shell: schtasks /end /tn 'Postgres Exporter'; schtasks /run /tn 'Postgres Exporter'
when:
- not ansible_check_mode
- _postgres_exporter_web_config is changed or
- _postgres_exporter_startup_script is changed or
_postgres_exporter_web_config is changed or
_postgres_exporter_scheduled_task is changed

- name: 'Windows | Ensure firewall rule for Postgres Exporter is allow'
Expand Down
20 changes: 20 additions & 0 deletions templates/Start-PostgresExporter.ps1.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
& '{{ postgres_exporter_install_path }}\postgres_exporter.exe' `
{% if postgres_exporter_tls_server_config | length or postgres_exporter_http_server_config | length or postgres_exporter_basic_auth_users | length %}
--web.config.file '{{ postgres_exporter_config_path }}\web_config.yaml' `
{% endif %}
--web.listen-address {{ postgres_exporter_web_listen_address }}:{{ postgres_exporter_web_listen_port }} `
--web.telemetry-path {{ postgres_exporter_web_telemetry_path }} `
{% for collector in postgres_exporter_collectors %}
--{{ collector }} `
{% endfor %}
{% if postgres_exporter_disable_default_metrics | bool %}
--disable-default-metrics `
{% endif %}
{% if postgres_exporter_disable_settings_metrics | bool %}
--disable-settings-metrics `
{% endif %}
{% if postgres_exporter_extend_query_path | length %}
--extend.query-path {{ postgres_exporter_extend_query_path }} `
{% endif %}
--log.level {{ postgres_exporter_log_level }} `
--log.format {{ postgres_exporter_log_format }}

0 comments on commit e915e9e

Please sign in to comment.