Skip to content

Commit b0c3d8d

Browse files
committed
feat: init role
0 parents  commit b0c3d8d

File tree

12 files changed

+215
-0
lines changed

12 files changed

+215
-0
lines changed

.ansible-lint

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
skip_list:
3+
- "204"
4+
- "yaml"

.github/workflows/push.yml

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
name: Push workflow
2+
3+
on: push
4+
5+
jobs:
6+
lint:
7+
runs-on: ubuntu-latest
8+
name: ansible-lint
9+
steps:
10+
- uses: actions/checkout@master
11+
- uses: actions/setup-python@v2
12+
- run: pip install ansible ansible-lint
13+
- run: ansible-lint --version
14+
- run: ansible-lint .
15+
16+
commitlint:
17+
runs-on: ubuntu-latest
18+
steps:
19+
- name: Checkout
20+
uses: actions/checkout@v2
21+
with:
22+
fetch-depth: 0
23+
- name: Lint Commit
24+
uses: wagoid/commitlint-github-action@v3
25+
26+
release:
27+
name: Publish new release
28+
needs: [lint, commitlint]
29+
if: github.ref == 'refs/heads/main' && github.event_name != 'pull_request'
30+
runs-on: ubuntu-latest
31+
steps:
32+
- name: Checkout
33+
uses: actions/checkout@v2
34+
- name: Setup Node.js
35+
uses: actions/setup-node@v2
36+
with:
37+
node-version: 14
38+
- name: Release
39+
env:
40+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
41+
run: npx semantic-release

.releaserc.json

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"branches": [
3+
"main"
4+
],
5+
"plugins": [
6+
"@semantic-release/commit-analyzer",
7+
"@semantic-release/release-notes-generator",
8+
[
9+
"@semantic-release/github",
10+
{
11+
"successComment": false,
12+
"releasedLabels": false
13+
}
14+
]
15+
]
16+
}

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2022 angristan
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Ansible role for Postgres exporter
2+
3+
This role will setup [postgres_exporter](https://github.com/prometheus-community/postgres_exporter) on any Linux machine using systemd.
4+
5+
## Role Variables
6+
7+
- `postgres_exporter_version`: the version of Postgres exporter that will be installed.
8+
9+
The role will download the Postgres exporter release on the deployer and upload the binary to the target host.
10+
11+
If the `/usr/local/bin/postgres_exporter` binary already exists, the role will skip the install steps. You can force them (to update, for instance), by setting `postgres_exporter_force_install` to true.
12+
13+
- `postgres_exporter_web_listen_address`: the address Node exporter will listen on. (`0.0.0.0:9187`)
14+
15+
## Example playbook
16+
17+
```yaml
18+
---
19+
- hosts: myhost
20+
roles: postgres-exporter
21+
```
22+
23+
## License
24+
25+
MIT. See LICENSE for more details.
26+
27+
## Author Information
28+
29+
See my other Ansible roles at [angristan/ansible-roles](https://github.com/angristan/ansible-roles).

defaults/main.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
postgres_exporter_version: 0.11.1
3+
postgres_exporter_force_install: false
4+
postgres_exporter_web_listen_address: "0.0.0.0:9187"

handlers/main.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
- name: Restart postgres_exporter
3+
ansible.builtin.systemd:
4+
daemon_reload: true
5+
name: postgres-exporter
6+
state: restarted

tasks/configure.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
- name: Copy the Postgres Exporter systemd service file
3+
ansible.builtin.template:
4+
src: postgres-exporter.service.j2
5+
dest: /etc/systemd/system/postgres-exporter.service
6+
owner: root
7+
group: root
8+
mode: 0644
9+
notify: Restart postgres-exporter

tasks/install.yml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
---
2+
- name: Download the postgres_exporter binary to a local folder
3+
ansible.builtin.get_url:
4+
url: "https://github.com/prometheus-community/postgres_exporter/releases/download/v{{ postgres_exporter_version }}/postgres_exporter-{{ postgres_exporter_version }}.linux-{{ go_arch_map[ansible_architecture] | default(ansible_architecture) }}.tar.gz"
5+
dest: "/tmp/postgres_exporter-{{ postgres_exporter_version }}.linux-{{ go_arch_map[ansible_architecture] | default(ansible_architecture) }}.tar.gz"
6+
mode: 0644
7+
register: _download_binary
8+
until: _download_binary is succeeded
9+
retries: 5
10+
delay: 2
11+
delegate_to: localhost
12+
check_mode: false
13+
14+
- name: Unarchive the postgres_exporter binary
15+
ansible.builtin.unarchive:
16+
src: "/tmp/postgres_exporter-{{ postgres_exporter_version }}.linux-{{ go_arch_map[ansible_architecture] | default(ansible_architecture) }}.tar.gz"
17+
dest: "/tmp"
18+
creates: "/tmp/postgres_exporter-v{{ postgres_exporter_version }}.linux-{{ go_arch_map[ansible_architecture] | default(ansible_architecture) }}/postgres_exporter"
19+
delegate_to: localhost
20+
check_mode: false
21+
22+
- name: Upload the postgres_exporter binary
23+
ansible.builtin.copy:
24+
src: "/tmp/postgres_exporter-{{ postgres_exporter_version }}.linux-{{ go_arch_map[ansible_architecture] | default(ansible_architecture) }}/postgres_exporter"
25+
dest: "/usr/local/bin/postgres_exporter"
26+
mode: 0750
27+
owner: postgres
28+
group: postgres
29+
notify: Restart postgres_exporter
30+
when: not ansible_check_mode

tasks/main.yml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
---
2+
- name: Check if postgres_exporter is installed
3+
ansible.builtin.stat:
4+
path: "/usr/local/bin/postgres_exporter"
5+
register: postgres_exporter_binary
6+
7+
- name: Install postgres_exporter
8+
ansible.builtin.include_tasks: install.yml
9+
when: not postgres_exporter_binary.stat.exists or postgres_exporter_force_install
10+
11+
- name: Configure postgres_exporter
12+
ansible.builtin.import_tasks: configure.yml
13+
tags:
14+
- postgres_exporter.configure
15+
16+
- name: Ensure Postgres exporter is enabled on boot
17+
ansible.builtin.systemd:
18+
daemon_reload: true
19+
name: postgres-exporter
20+
enabled: true
21+
state: started

0 commit comments

Comments
 (0)