Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improv: update variables and common role style, add molecule integration-test #21

Merged
merged 16 commits into from
Jun 17, 2024
Merged
29 changes: 17 additions & 12 deletions .github/workflows/molecule.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,23 @@ name: 'Molecule'
on:
pull_request:
push:
branches:
- main
branches: ['main']

jobs:
lint:
name: 'Lint'
runs-on: ubuntu-latest
runs-on: 'ubuntu-latest'
steps:
- name: 'Checkout the codebase'
uses: actions/checkout@v4
uses: 'actions/checkout@v4'

- name: 'Set up Python 3'
uses: actions/setup-python@v5
uses: 'actions/setup-python@v5'
with:
python-version: '3.x'

- name: 'Install linters'
run: pip3 install ansible-lint yamllint
run: pip3 install ansible-core==2.16.7 ansible-lint==24.5.0 yamllint==1.35.1

- name: 'Run linters'
run: |
Expand All @@ -29,28 +28,34 @@ jobs:

molecule:
name: 'Molecule'
needs: lint
runs-on: ubuntu-latest
needs: 'lint'
runs-on: 'ubuntu-latest'
strategy:
matrix:
include:
- distro: 'debian-11'
scenario: 'default'
- distro: 'debian-12'
scenario: 'default'
- distro: 'rockylinux-8'
scenario: 'default'
- distro: 'ubuntu-22.04'
- distro: 'rockylinux-9'
scenario: 'default'
- distro: 'ubuntu-20.04'
scenario: 'default'
- distro: 'ubuntu-22.04'
scenario: 'tls-and-basic-auth'
- distro: 'ubuntu-22.04'
scenario: 'integration-test'

steps:
- name: 'Checkout the codebase'
uses: actions/checkout@v4
uses: 'actions/checkout@v4'

- name: 'Testing an Ansible role with Molecule'
uses: gofrolist/molecule-action@v2
uses: 'gofrolist/molecule-action@v2'
with:
molecule_command: test
molecule_command: 'test'
molecule_args: --scenario-name ${{ matrix.scenario }}
env:
PY_COLORS: '1'
Expand Down
11 changes: 5 additions & 6 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,26 @@
name: 'Publish'
on:
release:
types:
- published
types: ['published']

jobs:
publish:
name: 'Publish'
runs-on: ubuntu-latest
runs-on: 'ubuntu-latest'
steps:
- name: 'Checkout the codebase'
uses: actions/checkout@v4
uses: 'actions/checkout@v4'

- name: 'Set up Python 3'
uses: actions/setup-python@v5
uses: 'actions/setup-python@v5'
with:
python-version: '3.x'

- name: 'Install ansible-core package'
run: pip3 install ansible-core

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

- name: 'Publish the role to the Ansible Galaxy'
Expand Down
13 changes: 6 additions & 7 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,25 @@ name: 'Release'
on:
workflow_run:
workflows: ['Molecule']
types: [completed]
branches:
- main
types: ['completed']
branches: ['main']

jobs:
release:
name: 'Release'
runs-on: ubuntu-latest
runs-on: 'ubuntu-latest'
if: ${{ github.repository_owner == 'antmelekhin' && github.event.workflow_run.conclusion == 'success' }}
steps:
- name: 'Checkout the codebase'
uses: actions/checkout@v4
uses: 'actions/checkout@v4'
with:
fetch-depth: 0
persist-credentials: false

- name: 'Semantic Release'
uses: cycjimmy/semantic-release-action@v4
uses: 'cycjimmy/semantic-release-action@v4'
with:
semantic_version: 23.0.8
semantic_version: '23.0.8'
extra_plugins: |
@semantic-release/[email protected]
@semantic-release/[email protected]
Expand Down
13 changes: 5 additions & 8 deletions .github/workflows/update-version.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,19 @@ on:
- cron: '59 23 * * 1'
workflow_dispatch:

env:
SOFTWARE: 'postgres_exporter'

jobs:
update-version:
name: 'Update version'
runs-on: ubuntu-latest
runs-on: 'ubuntu-latest'
permissions:
contents: write
pull-requests: write
contents: 'write'
pull-requests: 'write'
steps:
- name: 'Checkout the codebase'
uses: actions/checkout@v4
uses: 'actions/checkout@v4'

- name: 'Update version'
run: .github/scripts/update-version.sh $SOFTWARE
run: .github/scripts/update-version.sh postgres_exporter
env:
GITHUB_ACTOR: ${{ github.actor }}
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}
64 changes: 26 additions & 38 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,52 +25,40 @@ Requirements
- 20.04
- 22.04
- Windows
- 2016
- 2019
- all

Role Variables
--------------

Variables used to install the Postgres Exporter:

- `postgres_exporter_version` The version of Postgres Exporter to download (default: `0.15.0`).
- `postgres_exporter_archive_name` Postgres Exporter archive name.

Defaults:
- `postgres_exporter_version` The version of Postgres Exporter to install (default: `0.15.0`).
- `postgres_exporter_archive_name` The Postgres Exporter archive name. Defaults:
- `postgres_exporter-0.15.0.linux-amd64` (Linux)
- `postgres_exporter-0.15.0.windows-amd64` (Windows)

- `postgres_exporter_archive_extension` Postgres Exporter archive extension (default: `tar.gz`)
- `postgres_exporter_download_url` URL to download the Postgres Exporter archive (default: `https://github.com/prometheus-community/postgres_exporter/releases/download/v0.15.0`).

Variables used to configure the Postgres Exporter:

- `postgres_exporter_user` and `postgres_exporter_group` Unix user and group that will be created (default: `postgres`).
- `postgres_exporter_install_path` The Postgres Exporter installation directory (default: `/usr/local/bin`).
- `postgres_exporter_download_url` The Postgres Exporter archive download URL (default: `https://github.com/prometheus-community/postgres_exporter/releases/download/v0.15.0`).
- `postgres_exporter_download_path` Local path to download and extract the archive (default: `/tmp`).
- `postgres_exporter_user` and `postgres_exporter_group` System user and group that will be created (default: `postgres_exporter`).
- `postgres_exporter_install_path` The Postgres Exporter installation directory. Defaults:
- `/usr/local/bin` (Linux)
- `C:\Program Files\postgres_exporter` (Windows)
- `postgres_exporter_config_path` The Postgres Exporter directory, that contains the PostgreSQL connection settings. Defaults:
- `/etc/postgres_exporter` (Linux)
- `C:\Program Files\postgres_exporter` (Windows)
- `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`).
- `postgres_exporter_web_listen_address` Address to listen on for web interface and telemetry (default: `0.0.0.0`).
- `postgres_exporter_web_listen_port` The port to bind to (default: `9187`).
- `postgres_exporter_web_telemetry_path` The path at which to serve metrics (default: `metrics`).
- `postgres_exporter_collectors` List of collectors to use (default: `[]`).
- `postgres_exporter_tls_server_config` Certificate and key files for server to use to authenticate to client.
- `postgres_exporter_http_server_config` Enable HTTP/2 support. Note that HTTP/2 is only supported with TLS.
- `postgres_exporter_basic_auth_users` Users and password for basic authentication. Passwords are automatically hashed with bcrypt.
- `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.
- `postgres_exporter_data_source_user` When using `postgres_exporter_data_source_uri`, this variable is used to specify the username. Only for Linux.
- `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.
- `postgres_exporter_web_listen_address` The address to listen for the web interface and telemetry (default: `0.0.0.0`).
- `postgres_exporter_web_listen_port` The port number that Postgres Exporter listens on (default: `9187`).
- `postgres_exporter_web_telemetry_path` The path to expose metrics (default: `metrics`).
- `postgres_exporter_collectors` A list of collectors to use (default: `[]`).
- `postgres_exporter_tls_server_config` Certificate and key files for server to use to authenticate to client (default: `{}`).
- `postgres_exporter_http_server_config` Enable HTTP/2 support (default: `{}`). Note that HTTP/2 is only supported with TLS.
- `postgres_exporter_basic_auth_users` Users and password for basic authentication (default: `{}`). Passwords are automatically hashed with bcrypt.
- `postgres_exporter_disable_default_metrics` Use only metrics supplied from queries.yaml via `postgres_exporter_extend_query_path` (default: `false`).
- `postgres_exporter_disable_settings_metrics` Use the flag if you don't want to scrape pg_settings (default: `false`).
- `postgres_exporter_extend_query_path` Path to a YAML file containing custom queries to run. (default: `''`).
- `postgres_exporter_log_level` Postgres Exporter logging level.

Available values:
- `debug`
- `info` (default)
- `warn`
- `error`

- `postgres_exporter_log_format` Output format of log messages.

Available values:
- `logfmt` (default)
- `json`
- `postgres_exporter_log_level` The Postgres Exporter logging level. Supported levels are: `debug`, `info`, `warn`, `error` (default: `info`).
- `postgres_exporter_log_format` A log message format. Supported formats are: `logfmt`, `json` (default: `logfmt`).

Dependencies
------------
Expand All @@ -80,11 +68,11 @@ None.
Example Playbook
----------------

Install and configure the Postgres Exporter:
Install and configure the `Postgres Exporter`:

```yaml
---
- name: 'Setup Postgres Exporter'
- name: 'Setup the Postgres Exporter'
hosts: all

roles:
Expand Down
15 changes: 9 additions & 6 deletions defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,22 @@
# See available releases: https://github.com/prometheus-community/postgres_exporter/releases
postgres_exporter_version: '0.15.0'
postgres_exporter_archive_name: 'postgres_exporter-{{ postgres_exporter_version }}.{{ _postgres_exporter_os }}-{{ _postgres_exporter_architecture }}'
postgres_exporter_archive_extension: 'tar.gz'
postgres_exporter_download_url: 'https://github.com/prometheus-community/postgres_exporter/releases/download/v{{ postgres_exporter_version }}'
postgres_exporter_download_path: '/tmp'

# Postgres Exporter user.
postgres_exporter_user: 'postgres'
# The Postgres Exporter user and group
postgres_exporter_user: 'postgres_exporter'
postgres_exporter_group: '{{ postgres_exporter_user }}'

# Postgres Exporter directories.
# The Postgres Exporter directories
postgres_exporter_install_path: '{{ _postgres_exporter_install_path }}'
postgres_exporter_config_path: '{{ _postgres_exporter_config_path }}'

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

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

# Postgres Exporter TLS and basic authentication settings: https://github.com/prometheus/exporter-toolkit/blob/master/docs/web-configuration.md
# The Postgres Exporter TLS and basic authentication settings: https://github.com/prometheus/exporter-toolkit/blob/master/docs/web-configuration.md
postgres_exporter_tls_server_config: {}
postgres_exporter_http_server_config: {}
postgres_exporter_basic_auth_users: {}
2 changes: 1 addition & 1 deletion handlers/main.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
- name: 'Linux | Restart Postgres Exporter'
- name: 'Linux | Restart the Postgres Exporter'
ansible.builtin.systemd:
name: 'postgres_exporter'
daemon_reload: true
Expand Down
26 changes: 13 additions & 13 deletions meta/main.yml
Original file line number Diff line number Diff line change
@@ -1,37 +1,37 @@
---
galaxy_info:
author: antmelekhin
role_name: postgres_exporter
description: An Ansible role to install, configure and update Postgres Exporter.
author: 'antmelekhin'
role_name: 'postgres_exporter'
description: 'An Ansible role to install, configure and update the Postgres Exporter.'

license: MIT

min_ansible_version: '2.12'

platforms:
- name: Debian
- name: 'Debian'
versions:
- 'buster'
- 'bullseye'
- 'bookworm'
- name: EL
- name: 'EL'
versions:
- '7'
- '8'
- name: Ubuntu
- name: 'Ubuntu'
versions:
- 'bionic'
- 'focal'
- 'jammy'
- name: Windows
- name: 'Windows'
versions:
- '2016'
- '2019'
- 'all'

galaxy_tags:
- monitoring
- prometheus
- postgresql
- exporter
- 'exporter'
- 'metrics'
- 'monitoring'
- 'postgresql'
- 'prometheus'

dependencies: []
39 changes: 0 additions & 39 deletions molecule/default/converge.yml
Original file line number Diff line number Diff line change
@@ -1,44 +1,5 @@
---
- name: 'Prepare an Ansible host for Github Actions'
hosts: localhost
tasks:
- name: 'Install tar for delegated to localhost tasks'
community.general.apk:
name: 'tar'
update_cache: true
when: ansible_os_family == 'Alpine'

- name: 'Converge'
hosts: all
vars:
locale: 'en_US.UTF-8'

pre_tasks:
- name: 'Update APT cache'
ansible.builtin.apt:
update_cache: true
cache_valid_time: 600
when: ansible_os_family == 'Debian'

- name: 'Set database locale if using RedHat 8'
ansible.builtin.set_fact:
locale: 'C.UTF-8'
when:
- ansible_os_family == 'RedHat' and
ansible_distribution_major_version == '8'

roles:
- role: geerlingguy.postgresql
postgresql_users:
- name: 'molecule'
password: 'molecule'
role_attr_flags: 'SUPERUSER'
postgresql_databases:
- name: 'molecule'
lc_collate: '{{ locale }}'
lc_ctype: '{{ locale }}'
encoding: 'UTF-8'
template: 'template0'
owner: 'molecule'

- role: antmelekhin.postgres_exporter
Loading