Skip to content

custom ansible role for 0.30.7 #2049

Open
@irnmn

Description

@irnmn

Current Behavior

on version 0.30.5 it's good
- name: "Install {{ windows_exporter_bin_name }}"
ansible.windows.win_shell: >
msiexec /i "{{ windows_exporter_install_path }}{{ windows_exporter_bin_name }}-{{ windows_exporter_version }}-{{ windows_exporter_arch }}.msi" /qn --% ADDLOCAL=FirewallException ENABLED_COLLECTORS="{{ windows_exporter_collectors }}" LISTEN_PORT="{{ windows_exporter_port }}" TEXTFILE_DIRS="{{ windows_custom_metrics_path }}"
when: >
windows_exporter_version_check.stderr is not defined
or windows_exporter_version not in windows_exporter_version_check.stderr
or not windows_exporter_installed_check.stat.exists
register: windows_exporter_install_check
notify: "Restart {{ windows_exporter_bin_name }}"

- name: "Remove {{ windows_custom_metrics_cert }}"
  ansible.windows.win_file:
    path: '{{ windows_custom_metrics_path }}\{{ windows_custom_metrics_cert }}'
    state: absent

- name: "Create directory for custom_metrics"
  ansible.windows.win_file:
    path: "{{ windows_custom_metrics_path }}"
    state: directory

- name: "Generate windows custom SSL metrics"
  ansible.windows.win_shell: |
    $certificates = Get-ChildItem -Path cert:\LocalMachine\My | Where-Object { $_.Subject -match "CN={{ windows_cn_certs }}" }
    $outputFilePath = "{{ windows_custom_metrics_path }}\{{ windows_custom_metrics_cert }}"
    Set-Content -Path $outputFilePath -Encoding Ascii -NoNewline -Value ""
    foreach ($cert in $certificates) {
        $expirationDate = $cert.NotAfter
        $subject = $cert.Subject
        $unixTimestamp = [int][double]::Parse((Get-Date $expirationDate).ToUniversalTime().Subtract((Get-Date "1970-01-01")).TotalSeconds)
        Add-Content -Path $outputFilePath -Encoding Ascii -NoNewline -Value "certificate_expiration_date{subject=`"$subject`"} $unixTimestamp`n"
    }
    Add-Content -Path $outputFilePath -Encoding Ascii -NoNewline -Value "`n"
  notify: "Restart {{ windows_exporter_bin_name }}"

- name: "Check current version {{ windows_exporter_bin_name }}"
  ansible.windows.win_command: '"{{ windows_exporter_bin_path }}" --version'
  failed_when: false
  changed_when: false
  register: windows_exporter_version_check

- name: "Print version {{ windows_exporter_bin_name }}"
  ansible.builtin.debug:
    msg: "{{ windows_exporter_bin_name }} version: {{ windows_exporter_version_check.stderr | regex_search('version (\\d+\\.\\d+\\.\\d+)') }}"

- name: "Verify is responding to requests {{ windows_exporter_bin_name }}"
  ansible.windows.win_uri:
    url: http://localhost:9182/metrics
    return_content: true
  register: metrics_output

- name: "Print metrics_output {{ windows_exporter_bin_name }}"
  ansible.builtin.debug:
    msg:
      # -  all metrics "{{ metrics_output }}"
      - "Response URI: {{ metrics_output.response_uri }}"
      - "Status Code: {{ metrics_output.status_code }}"
      - "Status Description: {{ metrics_output.status_description }}"

- name: "Set Windows Exporter start mode to {{ windows_exporter_start_mode }}"
  ansible.windows.win_service:
    name: "{{ windows_exporter_bin_name }}"
    start_mode: auto
    state: started
  when: windows_exporter_install_check is succeeded
  notify: "Restart {{ windows_exporter_bin_name }}"

Expected Behavior

on version 0.30.7
FAILED! => {"changed": false, "exists": false, "msg": "Service 'windows_exporter' is not installed, need to set 'path' to create a new service"}

Steps To Reproduce

Environment

  • windows_exporter Version:
  • Windows Server Version:

windows_exporter logs

FAILED! => {"changed": false, "exists": false, "msg": "Service 'windows_exporter' is not installed, need to set 'path' to create a new service"}

Anything else?

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions