Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
francomile committed Jun 16, 2024
1 parent 596fb80 commit a0d6740
Show file tree
Hide file tree
Showing 11 changed files with 176 additions and 0 deletions.
7 changes: 7 additions & 0 deletions .ansible-lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
skip_list:
- no-handler
- command-instead-of-shell
- no-changed-when
- line-length
- fqcn-builtins
1 change: 1 addition & 0 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* @francomile
22 changes: 22 additions & 0 deletions .github/workflows/ansible_lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: "Lint Ansible roles"

on:
push:
branches-ignore:
- main

jobs:
ansible-lint:
name: "Ansible Lint"
runs-on: ubuntu-latest

steps:
- name: "Checkout"
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: "Lint Ansible Playbook"
uses: ansible/ansible-lint-action@v6.0.2
with:
path: ./
37 changes: 37 additions & 0 deletions .github/workflows/push_to_galaxy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
---
# This workflow requires a GALAXY_API_TOKEN secret present in the GitHub repository or organization. The TOKEN can be generated in https://galaxy.ansible.com/ui/token/

name: "Release role to Ansible Galaxy"
on:
push:
branches:
- main
tags:
- '*'

defaults:
run:
working-directory: "francomile.common"

jobs:
release:
name: "Release to Galaxy"
runs-on: ubuntu-latest
steps:
- name: "Check out."
uses: actions/checkout@v4
with:
path: "francomile.common"

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

- name: "Install Ansible."
run: pip3 install ansible-core

- name: "Import to Galaxy."
run: >-
ansible-galaxy role import --token ${{ secrets.GALAXY_API_TOKEN }}
francomile $(echo ${{ github.repository }} | cut -d/ -f2 )
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
.DS_Store
.vscode
.idea
.dccache
######## DON'T REMOVE THE BELOW FILE IGNORE #################
# ignore secret variables file for Ansible sensitive variables.
**/secret_vars.yaml*
23 changes: 23 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Ansible Prometheus Node Exporter Role

## Actions of the Role

* Install Prometheus node_exporter

## Common Usage

```yaml
roles:
- {
role: prom_node_exporter,
prom_node_exporter_basedir: "/opt/node_exporter",
prom_node_exporter_version: "v1.8.1",
tags: ["node-exporter"]
}
```

## Run the playbook

```shell
ansible-playbook -i inventory playbook.yaml -t "node-exporter"
```
3 changes: 3 additions & 0 deletions defaults/main.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
prom_node_exporter_basedir: "/opt/node_exporter"
prom_node_exporter_version: "v1.8.1"
6 changes: 6 additions & 0 deletions handlers/main.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
- name: "Restart node_exporter"
ansible.builtin.command:
cmd: "docker compose -f {{ prom_node_exporter_basedir }}/docker-compose.yaml up -d --force-recreate"
register: cmd_output
changed_when: cmd_output.rc != 0
28 changes: 28 additions & 0 deletions meta/main.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
---
galaxy_info:
role_name: prom_node_exporter
author: "Rubens Franco"
description: "Install Prometheus node_exporter"
license: "GNU GENERAL PUBLIC LICENSE v2"
min_ansible_version: "2.9"
platforms:
- name: Ubuntu
versions:
- "jammy"
- "focal"
- "bionic"
- name: Debian
versions:
- "bullseye"
- "buster"
- name: EL
versions:
- "9"
- "8"
galaxy_tags:
- monitoring
- observability
- prometheus
- exporter
- node
dependencies: []
23 changes: 23 additions & 0 deletions tasks/main.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
---
- name: "Prom Node Exporter | Create directories tree for node_exporter"
ansible.builtin.file:
path: "{{ prom_node_exporter_basedir }}"
state: directory
owner: root
group: root
mode: "0755"

- name: "Prom Node Exporter | Copy docker-compose.yaml template"
ansible.builtin.template:
src: "docker-compose.yaml.j2"
dest: "{{ prom_node_exporter_basedir }}/docker-compose.yaml"
owner: root
group: root
mode: "0640"
notify: "Restart node_exporter"

- name: "Prom Node Exporter | Start node_exporter"
ansible.builtin.command:
cmd: "docker compose -f {{ prom_node_exporter_basedir }}/docker-compose.yaml up -d"
register: cmd_output
changed_when: cmd_output.rc != 0
19 changes: 19 additions & 0 deletions templates/docker-compose.yaml.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
version: '3.9'

services:
node_exporter:
image: prom/node-exporter:{{ prom_node_exporter_version }}
container_name: node_exporter
command:
- '--path.rootfs=/host'
- --collector.filesystem.ignored-mount-points
- "^/(sys|proc|dev|host|etc|rootfs/var/lib/docker/containers|rootfs/var/lib/docker/overlay2)($$|/)"
deploy:
restart_policy:
condition: on-failure
network_mode: host
pid: host
volumes:
- '/:/host:ro,rslave'
logging:
driver: "journald"

0 comments on commit a0d6740

Please sign in to comment.