Skip to content

Commit 193e697

Browse files
authored
add windows support and new variables (#2)
* add supported platforms * add windows support * add molecule scenario for windows * add become as block * fix windows configure task * add new variables
1 parent 3fb657d commit 193e697

File tree

23 files changed

+292
-66
lines changed

23 files changed

+292
-66
lines changed

README.md

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,24 @@ Requirements
88

99
- Supported version of Ansible: 2.9 and highter.
1010
- `gnu-tar` on Mac as deployer host (`brew install gnu-tar`).
11+
- `pywinrm` is a python library for connection Ansible to Windows hosts via [WinRM](https://docs.ansible.com/ansible/latest/user_guide/windows_winrm.html).
1112
- List of all supported platforms described in role meta.
1213

1314
Role Variables
1415
--------------
1516

1617
- `postgres_exporter_version` The specific version of Postgres Exporter to download (default: `0.11.1`).
17-
- `postgres_exporter_archive_name` Postgres Exporter archive name (default: `postgres_exporter-{{ postgres_exporter_version }}.linux-{{ _postgres_exporter_architecture }}`).
18+
- `postgres_exporter_archive_name` Postgres Exporter archive name (default: `'postgres_exporter-0.11.1.linux-amd64'` or `'postgres_exporter-0.11.1.windows-amd64'`).
1819
- `postgres_exporter_archive_extension` Postgres Exporter archive extension (default: `tar.gz`)
19-
- `postgres_exporter_download_url` URL to download an archive with Postgres Exporter.
20+
- `postgres_exporter_download_url` URL to download an archive with Postgres Exporter (default: `https://github.com/prometheus-community/postgres_exporter/releases/download/v0.11.1`).
2021
- `postgres_exporter_user` and `postgres_exporter_group` Unix username and group (default: `postgres`).
2122
- `postgres_exporter_install_path` Path to Postgres Exporter installation directory (default: `/usr/local/bin`).
2223
- `postgres_exporter_data_source_name` Accepts URI form and key=value form arguments. The URI may contain the username and password to connect with. (default: `user=postgres host=/var/run/postgresql/ sslmode=disable`).
24+
- `postgres_exporter_listen_address` Address to listen on for web interface and telemetry (default: `0.0.0.0`).
25+
- `postgres_exporter_listen_port` The port to bind to (default: `9182`).
26+
- `postgres_exporter_metrics_path` The path at which to serve metrics (default: `metrics`).
27+
- `postgres_exporter_disable_default_metrics` Use only metrics supplied from queries.yaml via `postgres_exporter_extend_query_path` (default: `false`).
28+
- `postgres_exporter_disable_settings_metrics` Use the flag if you don't want to scrape pg_settings (default: `false`).
2329
- `postgres_exporter_extend_query_path` Path to a YAML file containing custom queries to run. (default: `''`).
2430
- `postgres_exporter_log_level` Postgres Exporter logging level.
2531

@@ -29,6 +35,12 @@ Role Variables
2935
- `warn`
3036
- `error`
3137

38+
- `postgres_exporter_log_format` Postgres Exporter logging format.
39+
40+
Available values:
41+
- `logfmt` (default)
42+
- `json`
43+
3244
Dependencies
3345
------------
3446

@@ -37,7 +49,7 @@ None.
3749
Example Playbook
3850
----------------
3951

40-
- Install and configure Postgres Exporter:
52+
- Install and configure `Postgres Exporter`:
4153

4254
```yaml
4355
---

defaults/main.yml

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
# See available releases: https://github.com/prometheus-community/postgres_exporter/releases
33
postgres_exporter_version: '0.11.1'
4-
postgres_exporter_archive_name: 'postgres_exporter-{{ postgres_exporter_version }}.linux-{{ _postgres_exporter_architecture }}'
4+
postgres_exporter_archive_name: 'postgres_exporter-{{ postgres_exporter_version }}.{{ _postgres_exporter_os }}-{{ _postgres_exporter_architecture }}'
55
postgres_exporter_archive_extension: 'tar.gz'
66
postgres_exporter_download_url: 'https://github.com/prometheus-community/postgres_exporter/releases/download/v{{ postgres_exporter_version }}'
77

@@ -10,11 +10,17 @@ postgres_exporter_user: 'postgres'
1010
postgres_exporter_group: '{{ postgres_exporter_user }}'
1111

1212
# Postgres Exporter directories.
13-
postgres_exporter_install_path: '/usr/local/bin'
13+
postgres_exporter_install_path: '{{ _postgres_exporter_install_path }}'
1414

1515
# See available environment variables: https://github.com/prometheus-community/postgres_exporter#environment-variables
16-
postgres_exporter_data_source_name: 'user=postgres host=/var/run/postgresql/ sslmode=disable'
16+
postgres_exporter_data_source_name: '{{ _postgres_exporter_data_source_name }}'
1717

1818
# See available settings flags: https://github.com/prometheus-community/postgres_exporter#flags
19+
postgres_exporter_listen_address: '0.0.0.0'
20+
postgres_exporter_listen_port: 9187
21+
postgres_exporter_metrics_path: '/metrics'
22+
postgres_exporter_disable_default_metrics: false
23+
postgres_exporter_disable_settings_metrics: false
1924
postgres_exporter_extend_query_path: ''
2025
postgres_exporter_log_level: 'info'
26+
postgres_exporter_log_format: 'logfmt'

handlers/main.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
- name: 'Restart Postgres Exporter'
2+
- name: 'Linux | Restart Postgres Exporter'
33
ansible.builtin.systemd:
44
name: postgres_exporter
55
state: restarted

meta/main.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,13 @@ galaxy_info:
1818
versions:
1919
- 'bionic'
2020
- 'focal'
21+
- name: Debian
22+
versions:
23+
- 'bullseye'
24+
- name: Windows
25+
versions:
26+
- '2016'
27+
- '2019'
2128

2229
galaxy_tags:
2330
- monitoring

molecule/default/converge.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
---
22
- name: 'Prepare an Ansible host for Github Actions'
33
hosts: localhost
4-
54
tasks:
65
- name: 'Install tar for delegated to localhost tasks'
76
apk:

molecule/default/molecule.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,7 @@ platforms:
2222
pre_build_image: true
2323
provisioner:
2424
name: ansible
25+
playbooks:
26+
verify: ../resources/tests/verify.yml
2527
verifier:
2628
name: ansible
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
---
2+
- name: 'Verify'
3+
hosts: all
4+
gather_facts: false
5+
6+
tasks:
7+
- name: 'Gathering Service Facts'
8+
ansible.builtin.service_facts:
9+
10+
- name: 'Assert that postgres_exporter service is enabled and running'
11+
ansible.builtin.assert:
12+
that:
13+
- ansible_facts.services['postgres_exporter.service'].state == 'running'
14+
- ansible_facts.services['postgres_exporter.service'].status == 'enabled'
15+
16+
- name: 'Verify postgres_exporter is responding to requests'
17+
ansible.builtin.uri:
18+
url: 'http://{{ ansible_host }}:9187/metrics'
19+
register: _result
20+
until: _result.status == 200
21+
retries: 120
22+
delay: 5
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
---
2+
- name: 'Verify'
3+
hosts: all
4+
gather_facts: false
5+
6+
tasks:
7+
- name: 'Verify postgres_exporter is responding to requests'
8+
ansible.builtin.uri:
9+
url: 'http://{{ ansible_host }}:9187/metrics'
10+
delegate_to: localhost
11+
register: _result
12+
until: _result.status == 200
13+
retries: 120
14+
delay: 5
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
- name: 'Converge'
3+
hosts: all
4+
roles:
5+
- role: antmelekhin.postgres_exporter
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
---
2+
dependency:
3+
name: galaxy
4+
driver:
5+
name: vagrant
6+
lint: |
7+
set -e
8+
yamllint .
9+
platforms:
10+
- name: instance
11+
box: 'jborean93/WindowsServer2019'
12+
interfaces:
13+
- network_name: forwarded_port
14+
guest: 9187
15+
host: 9187
16+
provisioner:
17+
name: ansible
18+
inventory:
19+
host_vars:
20+
instance:
21+
ansible_host: 127.0.0.1
22+
ansible_port: 55986
23+
ansible_user: vagrant
24+
ansible_password: vagrant
25+
ansible_connection: winrm
26+
ansible_winrm_scheme: https
27+
ansible_winrm_transport: ntlm
28+
ansible_winrm_server_cert_validation: ignore
29+
ansible_become: false
30+
playbooks:
31+
verify: ../resources/tests/win_verify.yml
32+
verifier:
33+
name: ansible

0 commit comments

Comments
 (0)