Skip to content

Commit 4ddf7e0

Browse files
authored
improv: update variables and common role style, add molecule integration-test (#21)
1 parent 8d0f6a0 commit 4ddf7e0

32 files changed

+353
-264
lines changed

.github/workflows/molecule.yml

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,23 @@ name: 'Molecule'
33
on:
44
pull_request:
55
push:
6-
branches:
7-
- main
6+
branches: ['main']
87

98
jobs:
109
lint:
1110
name: 'Lint'
12-
runs-on: ubuntu-latest
11+
runs-on: 'ubuntu-latest'
1312
steps:
1413
- name: 'Checkout the codebase'
15-
uses: actions/checkout@v4
14+
uses: 'actions/checkout@v4'
1615

1716
- name: 'Set up Python 3'
18-
uses: actions/setup-python@v5
17+
uses: 'actions/setup-python@v5'
1918
with:
2019
python-version: '3.x'
2120

2221
- name: 'Install linters'
23-
run: pip3 install ansible-lint yamllint
22+
run: pip3 install ansible-core==2.16.7 ansible-lint==24.5.0 yamllint==1.35.1
2423

2524
- name: 'Run linters'
2625
run: |
@@ -29,28 +28,34 @@ jobs:
2928
3029
molecule:
3130
name: 'Molecule'
32-
needs: lint
33-
runs-on: ubuntu-latest
31+
needs: 'lint'
32+
runs-on: 'ubuntu-latest'
3433
strategy:
3534
matrix:
3635
include:
36+
- distro: 'debian-11'
37+
scenario: 'default'
3738
- distro: 'debian-12'
3839
scenario: 'default'
3940
- distro: 'rockylinux-8'
4041
scenario: 'default'
41-
- distro: 'ubuntu-22.04'
42+
- distro: 'rockylinux-9'
43+
scenario: 'default'
44+
- distro: 'ubuntu-20.04'
4245
scenario: 'default'
4346
- distro: 'ubuntu-22.04'
4447
scenario: 'tls-and-basic-auth'
48+
- distro: 'ubuntu-22.04'
49+
scenario: 'integration-test'
4550

4651
steps:
4752
- name: 'Checkout the codebase'
48-
uses: actions/checkout@v4
53+
uses: 'actions/checkout@v4'
4954

5055
- name: 'Testing an Ansible role with Molecule'
51-
uses: gofrolist/molecule-action@v2
56+
uses: 'gofrolist/molecule-action@v2'
5257
with:
53-
molecule_command: test
58+
molecule_command: 'test'
5459
molecule_args: --scenario-name ${{ matrix.scenario }}
5560
env:
5661
PY_COLORS: '1'

.github/workflows/publish.yml

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,26 @@
22
name: 'Publish'
33
on:
44
release:
5-
types:
6-
- published
5+
types: ['published']
76

87
jobs:
98
publish:
109
name: 'Publish'
11-
runs-on: ubuntu-latest
10+
runs-on: 'ubuntu-latest'
1211
steps:
1312
- name: 'Checkout the codebase'
14-
uses: actions/checkout@v4
13+
uses: 'actions/checkout@v4'
1514

1615
- name: 'Set up Python 3'
17-
uses: actions/setup-python@v5
16+
uses: 'actions/setup-python@v5'
1817
with:
1918
python-version: '3.x'
2019

2120
- name: 'Install ansible-core package'
2221
run: pip3 install ansible-core
2322

2423
- name: 'Get an Ansible role name'
25-
id: get_role_name
24+
id: 'get_role_name'
2625
run: echo "ROLE_NAME=$(yq '.galaxy_info.role_name' meta/main.yml)" >> $GITHUB_OUTPUT
2726

2827
- name: 'Publish the role to the Ansible Galaxy'

.github/workflows/release.yml

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,26 +3,25 @@ name: 'Release'
33
on:
44
workflow_run:
55
workflows: ['Molecule']
6-
types: [completed]
7-
branches:
8-
- main
6+
types: ['completed']
7+
branches: ['main']
98

109
jobs:
1110
release:
1211
name: 'Release'
13-
runs-on: ubuntu-latest
12+
runs-on: 'ubuntu-latest'
1413
if: ${{ github.repository_owner == 'antmelekhin' && github.event.workflow_run.conclusion == 'success' }}
1514
steps:
1615
- name: 'Checkout the codebase'
17-
uses: actions/checkout@v4
16+
uses: 'actions/checkout@v4'
1817
with:
1918
fetch-depth: 0
2019
persist-credentials: false
2120

2221
- name: 'Semantic Release'
23-
uses: cycjimmy/semantic-release-action@v4
22+
uses: 'cycjimmy/semantic-release-action@v4'
2423
with:
25-
semantic_version: 23.0.8
24+
semantic_version: '23.0.8'
2625
extra_plugins: |
2726
@semantic-release/git@10.0.1
2827
@semantic-release/changelog@6.0.3

.github/workflows/update-version.yml

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,19 @@ on:
55
- cron: '59 23 * * 1'
66
workflow_dispatch:
77

8-
env:
9-
SOFTWARE: 'postgres_exporter'
10-
118
jobs:
129
update-version:
1310
name: 'Update version'
14-
runs-on: ubuntu-latest
11+
runs-on: 'ubuntu-latest'
1512
permissions:
16-
contents: write
17-
pull-requests: write
13+
contents: 'write'
14+
pull-requests: 'write'
1815
steps:
1916
- name: 'Checkout the codebase'
20-
uses: actions/checkout@v4
17+
uses: 'actions/checkout@v4'
2118

2219
- name: 'Update version'
23-
run: .github/scripts/update-version.sh $SOFTWARE
20+
run: .github/scripts/update-version.sh postgres_exporter
2421
env:
2522
GITHUB_ACTOR: ${{ github.actor }}
2623
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}

README.md

Lines changed: 26 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -25,52 +25,40 @@ Requirements
2525
- 20.04
2626
- 22.04
2727
- Windows
28-
- 2016
29-
- 2019
28+
- all
3029

3130
Role Variables
3231
--------------
3332

34-
Variables used to install the Postgres Exporter:
35-
36-
- `postgres_exporter_version` The version of Postgres Exporter to download (default: `0.15.0`).
37-
- `postgres_exporter_archive_name` Postgres Exporter archive name.
38-
39-
Defaults:
33+
- `postgres_exporter_version` The version of Postgres Exporter to install (default: `0.15.0`).
34+
- `postgres_exporter_archive_name` The Postgres Exporter archive name. Defaults:
4035
- `postgres_exporter-0.15.0.linux-amd64` (Linux)
4136
- `postgres_exporter-0.15.0.windows-amd64` (Windows)
42-
43-
- `postgres_exporter_archive_extension` Postgres Exporter archive extension (default: `tar.gz`)
44-
- `postgres_exporter_download_url` URL to download the Postgres Exporter archive (default: `https://github.com/prometheus-community/postgres_exporter/releases/download/v0.15.0`).
45-
46-
Variables used to configure the Postgres Exporter:
47-
48-
- `postgres_exporter_user` and `postgres_exporter_group` Unix user and group that will be created (default: `postgres`).
49-
- `postgres_exporter_install_path` The Postgres Exporter installation directory (default: `/usr/local/bin`).
37+
- `postgres_exporter_download_url` The Postgres Exporter archive download URL (default: `https://github.com/prometheus-community/postgres_exporter/releases/download/v0.15.0`).
38+
- `postgres_exporter_download_path` Local path to download and extract the archive (default: `/tmp`).
39+
- `postgres_exporter_user` and `postgres_exporter_group` System user and group that will be created (default: `postgres_exporter`).
40+
- `postgres_exporter_install_path` The Postgres Exporter installation directory. Defaults:
41+
- `/usr/local/bin` (Linux)
42+
- `C:\Program Files\postgres_exporter` (Windows)
43+
- `postgres_exporter_config_path` The Postgres Exporter directory, that contains the PostgreSQL connection settings. Defaults:
44+
- `/etc/postgres_exporter` (Linux)
45+
- `C:\Program Files\postgres_exporter` (Windows)
5046
- `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`).
51-
- `postgres_exporter_web_listen_address` Address to listen on for web interface and telemetry (default: `0.0.0.0`).
52-
- `postgres_exporter_web_listen_port` The port to bind to (default: `9187`).
53-
- `postgres_exporter_web_telemetry_path` The path at which to serve metrics (default: `metrics`).
54-
- `postgres_exporter_collectors` List of collectors to use (default: `[]`).
55-
- `postgres_exporter_tls_server_config` Certificate and key files for server to use to authenticate to client.
56-
- `postgres_exporter_http_server_config` Enable HTTP/2 support. Note that HTTP/2 is only supported with TLS.
57-
- `postgres_exporter_basic_auth_users` Users and password for basic authentication. Passwords are automatically hashed with bcrypt.
47+
- `postgres_exporter_data_source_uri` An alternative to `postgres_exporter_data_source_name` which exclusively accepts the hostname without a username and password component. Only for Linux.
48+
- `postgres_exporter_data_source_user` When using `postgres_exporter_data_source_uri`, this variable is used to specify the username. Only for Linux.
49+
- `postgres_exporter_data_source_pass` When using `postgres_exporter_data_source_uri`, this variable is used to specify the password to connect with. Only for Linux.
50+
- `postgres_exporter_web_listen_address` The address to listen for the web interface and telemetry (default: `0.0.0.0`).
51+
- `postgres_exporter_web_listen_port` The port number that Postgres Exporter listens on (default: `9187`).
52+
- `postgres_exporter_web_telemetry_path` The path to expose metrics (default: `metrics`).
53+
- `postgres_exporter_collectors` A list of collectors to use (default: `[]`).
54+
- `postgres_exporter_tls_server_config` Certificate and key files for server to use to authenticate to client (default: `{}`).
55+
- `postgres_exporter_http_server_config` Enable HTTP/2 support (default: `{}`). Note that HTTP/2 is only supported with TLS.
56+
- `postgres_exporter_basic_auth_users` Users and password for basic authentication (default: `{}`). Passwords are automatically hashed with bcrypt.
5857
- `postgres_exporter_disable_default_metrics` Use only metrics supplied from queries.yaml via `postgres_exporter_extend_query_path` (default: `false`).
5958
- `postgres_exporter_disable_settings_metrics` Use the flag if you don't want to scrape pg_settings (default: `false`).
6059
- `postgres_exporter_extend_query_path` Path to a YAML file containing custom queries to run. (default: `''`).
61-
- `postgres_exporter_log_level` Postgres Exporter logging level.
62-
63-
Available values:
64-
- `debug`
65-
- `info` (default)
66-
- `warn`
67-
- `error`
68-
69-
- `postgres_exporter_log_format` Output format of log messages.
70-
71-
Available values:
72-
- `logfmt` (default)
73-
- `json`
60+
- `postgres_exporter_log_level` The Postgres Exporter logging level. Supported levels are: `debug`, `info`, `warn`, `error` (default: `info`).
61+
- `postgres_exporter_log_format` A log message format. Supported formats are: `logfmt`, `json` (default: `logfmt`).
7462

7563
Dependencies
7664
------------
@@ -80,11 +68,11 @@ None.
8068
Example Playbook
8169
----------------
8270

83-
Install and configure the Postgres Exporter:
71+
Install and configure the `Postgres Exporter`:
8472

8573
```yaml
8674
---
87-
- name: 'Setup Postgres Exporter'
75+
- name: 'Setup the Postgres Exporter'
8876
hosts: all
8977

9078
roles:

defaults/main.yml

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,22 @@
22
# See available releases: https://github.com/prometheus-community/postgres_exporter/releases
33
postgres_exporter_version: '0.15.0'
44
postgres_exporter_archive_name: 'postgres_exporter-{{ postgres_exporter_version }}.{{ _postgres_exporter_os }}-{{ _postgres_exporter_architecture }}'
5-
postgres_exporter_archive_extension: 'tar.gz'
65
postgres_exporter_download_url: 'https://github.com/prometheus-community/postgres_exporter/releases/download/v{{ postgres_exporter_version }}'
6+
postgres_exporter_download_path: '/tmp'
77

8-
# Postgres Exporter user.
9-
postgres_exporter_user: 'postgres'
8+
# The Postgres Exporter user and group
9+
postgres_exporter_user: 'postgres_exporter'
1010
postgres_exporter_group: '{{ postgres_exporter_user }}'
1111

12-
# Postgres Exporter directories.
12+
# The Postgres Exporter directories
1313
postgres_exporter_install_path: '{{ _postgres_exporter_install_path }}'
1414
postgres_exporter_config_path: '{{ _postgres_exporter_config_path }}'
1515

16-
# See available environment variables: https://github.com/prometheus-community/postgres_exporter#environment-variables
16+
# The Postgres Exporter connection settings
1717
postgres_exporter_data_source_name: '{{ _postgres_exporter_data_source_name }}'
18+
postgres_exporter_data_source_uri: ''
19+
postgres_exporter_data_source_user: ''
20+
postgres_exporter_data_source_pass: ''
1821

1922
# See available settings flags: https://github.com/prometheus-community/postgres_exporter#flags
2023
postgres_exporter_web_listen_address: '0.0.0.0'
@@ -27,7 +30,7 @@ postgres_exporter_extend_query_path: ''
2730
postgres_exporter_log_level: 'info'
2831
postgres_exporter_log_format: 'logfmt'
2932

30-
# Postgres Exporter TLS and basic authentication settings: https://github.com/prometheus/exporter-toolkit/blob/master/docs/web-configuration.md
33+
# The Postgres Exporter TLS and basic authentication settings: https://github.com/prometheus/exporter-toolkit/blob/master/docs/web-configuration.md
3134
postgres_exporter_tls_server_config: {}
3235
postgres_exporter_http_server_config: {}
3336
postgres_exporter_basic_auth_users: {}

handlers/main.yml

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

meta/main.yml

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,37 @@
11
---
22
galaxy_info:
3-
author: antmelekhin
4-
role_name: postgres_exporter
5-
description: An Ansible role to install, configure and update Postgres Exporter.
3+
author: 'antmelekhin'
4+
role_name: 'postgres_exporter'
5+
description: 'An Ansible role to install, configure and update the Postgres Exporter.'
66

77
license: MIT
88

99
min_ansible_version: '2.12'
1010

1111
platforms:
12-
- name: Debian
12+
- name: 'Debian'
1313
versions:
1414
- 'buster'
1515
- 'bullseye'
1616
- 'bookworm'
17-
- name: EL
17+
- name: 'EL'
1818
versions:
1919
- '7'
2020
- '8'
21-
- name: Ubuntu
21+
- name: 'Ubuntu'
2222
versions:
2323
- 'bionic'
2424
- 'focal'
2525
- 'jammy'
26-
- name: Windows
26+
- name: 'Windows'
2727
versions:
28-
- '2016'
29-
- '2019'
28+
- 'all'
3029

3130
galaxy_tags:
32-
- monitoring
33-
- prometheus
34-
- postgresql
35-
- exporter
31+
- 'exporter'
32+
- 'metrics'
33+
- 'monitoring'
34+
- 'postgresql'
35+
- 'prometheus'
3636

3737
dependencies: []

molecule/default/converge.yml

Lines changed: 0 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,5 @@
11
---
2-
- name: 'Prepare an Ansible host for Github Actions'
3-
hosts: localhost
4-
tasks:
5-
- name: 'Install tar for delegated to localhost tasks'
6-
community.general.apk:
7-
name: 'tar'
8-
update_cache: true
9-
when: ansible_os_family == 'Alpine'
10-
112
- name: 'Converge'
123
hosts: all
13-
vars:
14-
locale: 'en_US.UTF-8'
15-
16-
pre_tasks:
17-
- name: 'Update APT cache'
18-
ansible.builtin.apt:
19-
update_cache: true
20-
cache_valid_time: 600
21-
when: ansible_os_family == 'Debian'
22-
23-
- name: 'Set database locale if using RedHat 8'
24-
ansible.builtin.set_fact:
25-
locale: 'C.UTF-8'
26-
when:
27-
- ansible_os_family == 'RedHat' and
28-
ansible_distribution_major_version == '8'
29-
304
roles:
31-
- role: geerlingguy.postgresql
32-
postgresql_users:
33-
- name: 'molecule'
34-
password: 'molecule'
35-
role_attr_flags: 'SUPERUSER'
36-
postgresql_databases:
37-
- name: 'molecule'
38-
lc_collate: '{{ locale }}'
39-
lc_ctype: '{{ locale }}'
40-
encoding: 'UTF-8'
41-
template: 'template0'
42-
owner: 'molecule'
43-
445
- role: antmelekhin.postgres_exporter

0 commit comments

Comments
 (0)