Skip to content

Commit

Permalink
Merge pull request #305 from anviar/main
Browse files Browse the repository at this point in the history
feat: Add bind_exporter role
  • Loading branch information
gardar authored Feb 25, 2024
2 parents a079430 + 3f9aa6e commit 6e134ee
Show file tree
Hide file tree
Showing 25 changed files with 919 additions and 0 deletions.
85 changes: 85 additions & 0 deletions roles/bind_exporter/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
<p><img src="https://www.circonus.com/wp-content/uploads/2015/03/sol-icon-itOps.png" alt="graph logo" title="graph" align="right" height="60" /></p>

# Ansible Role: BIND exporter


Deploy prometheus [bind exporter](https://github.com/prometheus-community/bind_exporter) using ansible.

## Requirements

- Ansible >= 2.9 (It might work on previous versions, but we cannot guarantee it)
- gnu-tar on Mac deployer host (`brew install gnu-tar`)
- Passlib is required when using the basic authentication feature (`pip install passlib[bcrypt]`)

## Role Variables
All variables which can be overridden are stored in [defaults/main.yml](defaults/main.yml) file as well as in [meta/argument_specs.yml](meta/argument_specs.yml).
Please refer to the [collection docs](https://prometheus-community.github.io/ansible/branch/main/bind_exporter_role.html) for description and default values of the variables.

## Example

### Playbook

Use it in a playbook as follows:
```yaml
- hosts: all
collections:
- prometheus.prometheus
roles:
- prometheus.prometheus.bind_exporter
```
### TLS config
Before running bind_exporter role, the user needs to provision their own certificate and key.
```yaml
- hosts: all
pre_tasks:
- name: Create bind_exporter cert dir
ansible.builtin.file:
path: "/etc/bind_exporter"
state: directory
owner: root
group: root

- name: Create cert and key
community.crypto.x509_certificate:
path: /etc/bind_exporter/tls.cert
csr_path: /etc/bind_exporter/tls.csr
privatekey_path: /etc/bind_exporter/tls.key
provider: selfsigned
collections:
- prometheus.prometheus
roles:
- prometheus.prometheus.bind_exporter
vars:
bind_exporter_tls_server_config:
cert_file: /etc/bind_exporter/tls.cert
key_file: /etc/bind_exporter/tls.key
bind_exporter_basic_auth_users:
randomuser: examplepassword
```
### Demo site
We provide an example site that demonstrates a full monitoring solution based on prometheus and grafana. The repository with code and links to running instances is [available on github](https://github.com/prometheus/demo-site) and the site is hosted on [DigitalOcean](https://digitalocean.com).
## Local Testing
The preferred way of locally testing the role is to use Docker and [molecule](https://github.com/ansible-community/molecule) (v3.x). You will have to install Docker on your system. See "Get started" for a Docker package suitable for your system. Running your tests is as simple as executing `molecule test`.

## Continuous Integration

Combining molecule and circle CI allows us to test how new PRs will behave when used with multiple ansible versions and multiple operating systems. This also allows use to create test scenarios for different role configurations. As a result we have quite a large test matrix which can take more time than local testing, so please be patient.

## Contributing

See [contributor guideline](CONTRIBUTING.md).

## Troubleshooting

See [troubleshooting](TROUBLESHOOTING.md).

## License

This project is licensed under MIT License. See [LICENSE](/LICENSE) for more details.
20 changes: 20 additions & 0 deletions roles/bind_exporter/TROUBLESHOOTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Troubleshooting

## Bad requests (HTTP 400)

This role downloads checksums from the Github project to verify the integrity of artifacts installed on your servers. When downloading the checksums, a "bad request" error might occur.

This happens in environments which (knowningly or unknowling) use the [netrc mechanism](https://www.gnu.org/software/inetutils/manual/html_node/The-_002enetrc-file.html) to auto-login into servers.

Unless netrc is needed by your playbook and ansible roles, please unset the var like so:

```
$ NETRC= ansible-playbook ...
```

Or:

```
$ export NETRC=
$ ansible-playbook ...
```
26 changes: 26 additions & 0 deletions roles/bind_exporter/defaults/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
---
bind_exporter_version: 0.7.0
bind_exporter_binary_local_dir: ""
bind_exporter_binary_url: "https://github.com/{{ _bind_exporter_repo }}/releases/download/v{{ bind_exporter_version }}/\
bind_exporter-{{ bind_exporter_version }}.linux-{{ go_arch }}.tar.gz"
bind_exporter_checksums_url: "https://github.com/{{ _bind_exporter_repo }}/releases/download/v{{ bind_exporter_version }}/sha256sums.txt"
bind_exporter_skip_install: false

bind_exporter_web_listen_address: "0.0.0.0:9119"
bind_exporter_web_telemetry_path: "/metrics"

bind_exporter_stats_url: "http://localhost:8053/"
bind_exporter_timeout: "10s"
bind_exporter_pid_file: "/run/named/named.pid"
bind_exporter_stats_version: "auto"
bind_exporter_stats_groups: []

bind_exporter_tls_server_config: {}
bind_exporter_http_server_config: {}
bind_exporter_basic_auth_users: {}

# Internal variables.
bind_exporter_binary_install_dir: "/usr/local/bin"
bind_exporter_config_dir: "/etc/bind_exporter"
bind_exporter_system_group: "bind-exp"
bind_exporter_system_user: "{{ bind_exporter_system_group }}"
10 changes: 10 additions & 0 deletions roles/bind_exporter/handlers/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
- name: Restart bind_exporter
listen: "restart bind_exporter"
become: true
ansible.builtin.systemd:
daemon_reload: true
name: bind_exporter
state: restarted
when:
- not ansible_check_mode
90 changes: 90 additions & 0 deletions roles/bind_exporter/meta/argument_specs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
---
# yamllint disable rule:line-length
argument_specs:
main:
short_description: "Prometheus BIND Exporter"
description:
- "Deploy prometheus L(bind_exporter,https://github.com/prometheus-community/bind_exporter) using ansible"
author:
- "Prometheus Community"
options:
bind_exporter_version:
description: "BIND exporter package version. Also accepts latest as parameter."
default: "0.7.0"
bind_exporter_skip_install:
description: "BIND installation tasks gets skipped when set to true."
type: bool
default: false
bind_exporter_binary_local_dir:
description:
- "Enables the use of local packages instead of those distributed on github."
- "The parameter may be set to a directory where the C(bind_exporter) binary is stored on the host where ansible is run."
- "This overrides the I(bind_exporter_version) parameter"
bind_exporter_binary_url:
description: "URL of the bind_exporter binaries .tar.gz file"
default: "https://github.com/{{ _bind_exporter_repo }}/download/v{{ bind_exporter_version }}/bind_exporter-{{ bind_exporter_version }}.linux-{{ go_arch }}.tar.gz"
bind_exporter_checksums_url:
description: "URL of the bind_exporter checksums file"
default: "https://github.com/{{ _bind_exporter_repo }}/releases/download/v{{ bind_exporter_version }}/sha256sums.txt"
bind_exporter_web_listen_address:
description: "Address on which bind_exporter will listen"
default: "0.0.0.0:9119"
bind_exporter_web_telemetry_path:
description: "Path under which to expose metrics"
default: "/metrics"
bind_exporter_config_dir:
description: "The path where exporter configuration is stored"
default: "/etc/bind_exporter"
bind_exporter_stats_url:
description: "HTTP XML API address of BIND server"
default: "http://localhost:8053/"
bind_exporter_timeout:
description: "Timeout for trying to get stats from BIND server"
default: "10s"
bind_exporter_pid_file:
description: "Path to BIND's pid file to export process information"
default: "/run/named/named.pid"
bind_exporter_stats_version:
description: "BIND statistics version."
default: "auto"
choices:
- "auto"
- "json"
- "xml"
- "xml.v3"
bind_exporter_stats_groups:
description: "List of statistics to collect"
default: []
type: "list"
choices:
- "server"
- "view"
- "tasks"
bind_exporter_tls_server_config:
description:
- "Configuration for TLS authentication."
- "Keys and values are the same as in L(prometheus docs,https://github.com/prometheus/exporter-toolkit/blob/master/docs/web-configuration.md)."
type: "dict"
bind_exporter_http_server_config:
description:
- "Config for HTTP/2 support."
- "Keys and values are the same as in L(prometheus docs,https://github.com/prometheus/exporter-toolkit/blob/master/docs/web-configuration.md)."
type: "dict"
bind_exporter_basic_auth_users:
description: "Dictionary of users and password for basic authentication. Passwords are automatically hashed with bcrypt."
type: "dict"
bind_exporter_binary_install_dir:
description:
- "I(Advanced)"
- "Directory to install bind_exporter binary"
default: "/usr/local/bin"
bind_exporter_system_group:
description:
- "I(Advanced)"
- "System group for BIND Exporter"
default: "bind-exp"
bind_exporter_system_user:
description:
- "I(Advanced)"
- "BIND Exporter user"
default: "bind-exp"
33 changes: 33 additions & 0 deletions roles/bind_exporter/meta/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
---
galaxy_info:
author: "Prometheus Community"
description: "Prometheus BIND Exporter"
license: "Apache"
min_ansible_version: "2.9"
platforms:
- name: "Ubuntu"
versions:
- "focal"
- "jammy"
- name: "Debian"
versions:
- "bullseye"
- "buster"
- name: "EL"
versions:
- "7"
- "8"
- "9"
- name: "Fedora"
versions:
- "37"
- '38'
galaxy_tags:
- "monitoring"
- "prometheus"
- "exporter"
- "metrics"
- "system"
- "bind"
- "named"
- "dns"
21 changes: 21 additions & 0 deletions roles/bind_exporter/molecule/alternative/molecule.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
---
provisioner:
inventory:
group_vars:
all:
bind_exporter_binary_local_dir: "/tmp/bind_exporter-linux-amd64"
bind_exporter_web_listen_address:
- '127.0.0.1:8080'
- '127.0.1.1:8080'
bind_exporter_stats_groups:
- server
- view
bind_exporter_tls_server_config:
cert_file: /etc/bind_exporter/tls.cert
key_file: /etc/bind_exporter/tls.key
bind_exporter_http_server_config:
http2: true
bind_exporter_basic_auth_users:
randomuser: examplepassword
go_arch: amd64
bind_exporter_version: 0.7.0
80 changes: 80 additions & 0 deletions roles/bind_exporter/molecule/alternative/prepare.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
---
- name: Run local preparation
hosts: localhost
gather_facts: false
tasks:
- name: Download bind_exporter binary to local folder
become: false
ansible.builtin.get_url:
url: "https://github.com/prometheus-community/bind_exporter/releases/download/v{{\
\ bind_exporter_version }}/bind_exporter-{{ bind_exporter_version\
\ }}.linux-{{ go_arch }}.tar.gz"
dest: "/tmp/bind_exporter-{{ bind_exporter_version }}.linux-{{ go_arch\
\ }}.tar.gz"
mode: 0644
register: _download_binary
until: _download_binary is succeeded
retries: 5
delay: 2
check_mode: false

- name: Unpack bind_exporter binary
become: false
ansible.builtin.unarchive:
src: "/tmp/bind_exporter-{{ bind_exporter_version }}.linux-{{ go_arch\
\ }}.tar.gz"
dest: "/tmp"
creates: "/tmp/bind_exporter-{{ bind_exporter_version }}.linux-{{ go_arch\
\ }}/bind_exporter"
check_mode: false

- name: Link to bind_exporter binaries directory
become: false
ansible.builtin.file:
src: "/tmp/bind_exporter-{{ bind_exporter_version }}.linux-amd64"
dest: "/tmp/bind_exporter-linux-amd64"
state: link
check_mode: false

- name: Install pyOpenSSL for certificate generation
ansible.builtin.pip:
name: "pyOpenSSL"

- name: Create private key
community.crypto.openssl_privatekey:
path: "/tmp/tls.key"

- name: Create CSR
community.crypto.openssl_csr:
path: "/tmp/tls.csr"
privatekey_path: "/tmp/tls.key"

- name: Create certificate
community.crypto.x509_certificate:
path: "/tmp/tls.cert"
csr_path: "/tmp/tls.csr"
privatekey_path: "/tmp/tls.key"
provider: selfsigned

- name: Run target preparation
hosts: all
any_errors_fatal: true
tasks:
- name: Create bind_exporter cert dir
ansible.builtin.file:
path: "{{ bind_exporter_tls_server_config.cert_file | dirname }}"
state: directory
owner: root
group: root
mode: u+rwX,g+rwX,o=rX

- name: Copy cert and key
ansible.builtin.copy:
src: "{{ item.src }}"
dest: "{{ item.dest }}"
mode: "{{ item.mode | default('0644') }}"
loop:
- src: "/tmp/tls.cert"
dest: "{{ bind_exporter_tls_server_config.cert_file }}"
- src: "/tmp/tls.key"
dest: "{{ bind_exporter_tls_server_config.key_file }}"
Loading

0 comments on commit 6e134ee

Please sign in to comment.