Skip to content

improve local extraction #4

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

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
MIT License

Copyright (c) 2019 Agnesius Santo Naibaho
Copyright (c) 2021 L3D <[email protected]>

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
80 changes: 39 additions & 41 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,55 +1,53 @@
Ansible Role Nginx Exporter
=========
Ansible Role Nginx Exporter
=============================

[![Build Status](https://travis-ci.com/cloudweeb/ansible-role-nginx_exporter.svg?branch=master)](https://travis-ci.com/cloudweeb/ansible-role-nginx_exporter)

Ansible role to install Nginx Prometheus Exporter
Ansible role to install [Nginx Prometheus Exporter](https://github.com/nginxinc/nginx-prometheus-exporter)

Requirements
------------
Requirements
--------------

None

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

| variable | default | comment |
|-------------------------------|-----------------------------------|-------------------------------|
| nginx_exporter_version | 0.3.0 | nginx exporter version |
| nginx_exporter_nginx_plus | false | set true if use nginx plus |
| nginx_exporter_listen_address | 0.0.0.0:9113 | nginx exporter listen address |
| nginx_exporter_scrape_uri | <http://127.0.0.1:8080/stub_status> | nginx status url |
| variable | default | comment |
|---------------------------------|-------------------------------------|-------------------------------|
| `nginx_exporter_version` | `0.9.0` | nginx exporter version |
| `nginx_exporter_nginx_plus` | `false` | set true if use nginx plus |
| `nginx_exporter_listen_address` | `0.0.0.0:9113` | nginx exporter listen address |
| `nginx_exporter_scrape_uri` | `http://127.0.0.1:8080/stub_status` | nginx status url |

Dependencies
------------
Dependencies
--------------

geerlingguy.nginx
You need a nginx server with stub_status enabled. For example ``geerlingguy.nginx``.

Example Playbook
----------------

- hosts: servers
vars:
nginx_vhosts:
- listen: "127.0.0.1:8080 default"
server_name: "_"
filename: "status.conf"
extra_parameters: |
location / {
stub_status on;
access_log off;
}

roles:
- geerlingguy.nginx
- cloudweeb.nginx_exporter

License
Example Playbook
------------------
```yaml
- hosts: servers
vars:
nginx_vhosts:
- listen: "127.0.0.1:8080 default"
server_name: "_"
filename: "status.conf"
extra_parameters: |
location / {
stub_status on;
access_log off;
}
roles:
- geerlingguy.nginx
- cloudweeb.nginx_exporter
```

License
-------

MIT / BSD

Author Information
Author Information
------------------

Agnesius Santo Naibaho
+ Agnesius Santo Naibaho
+ L3D *([DO1JLR](https://github.com/do1jlr))*
7 changes: 5 additions & 2 deletions defaults/main.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
---

nginx_exporter_version: 0.3.0
nginx_exporter_version: '0.9.0'
nginx_exporter_nginx_plus: false

nginx_exporter_system_group: nginx-exp
nginx_exporter_system_user: "{{ nginx_exporter_system_group }}"

nginx_exporter_download_url: >
https://github.com/nginxinc/nginx-prometheus-exporter/releases/download/v{{ nginx_exporter_version }}/nginx-prometheus-exporter-{{ nginx_exporter_version }}-linux-{{ go_arch }}.tar.gz
https://github.com/nginxinc/nginx-prometheus-exporter/releases/download/v{{ nginx_exporter_version }}/nginx-prometheus-exporter_{{ nginx_exporter_version }}_linux_{{ go_arch }}.tar.gz

nginx_exporter_listen_address: 0.0.0.0:9113
nginx_exporter_scrape_uri: http://127.0.0.1:8080/stub_status

# perform simple version check for this role? (true is recomended)
submodules_versioncheck: false
6 changes: 3 additions & 3 deletions handlers/main.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---

- name: restart nginx_exporter
systemd:
- name: systemctl restart nginx_exporter
become: true
ansible.builtin.systemd:
name: nginx_exporter
state: restarted
daemon_reload: true
19 changes: 8 additions & 11 deletions meta/main.yml
Original file line number Diff line number Diff line change
@@ -1,26 +1,23 @@
---
galaxy_info:
role_name: nginx_exporter
author: Agnesius Santo Naibaho
description: Install Nginx Exporter Prometheus
company: Cloudweeb
author: do1jlr
description: Install Nginx Prometheus Exporter

license: MIT

min_ansible_version: 2.7
min_ansible_version: 2.11

platforms:
- name: EL
versions:
- 7
versions: all
- name: Debian
versions:
- stretch
versions: all
- name: Ubuntu
versions: all

galaxy_tags:
- nginx
- monitoring
- prometheus

dependencies:
- geerlingguy.nginx
- exporter
7 changes: 4 additions & 3 deletions tasks/config.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
---

- name: Create nginx_exporter systemd file
template:
become: true
ansible.builtin.template:
src: nginx_exporter.service.j2
dest: /etc/systemd/system/nginx_exporter.service
notify: restart nginx_exporter
mode: '0644'
notify: systemctl restart nginx_exporter
24 changes: 13 additions & 11 deletions tasks/install.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
---

- name: Create nginx_exporter system group
group:
become: true
ansible.builtin.group:
name: "{{ nginx_exporter_system_group }}"
state: present
system: true

- name: Create the nginx_exporter user
user:
become: true
ansible.builtin.user:
name: "{{ nginx_exporter_system_user }}"
groups: "{{ nginx_exporter_system_group }}"
append: true
Expand All @@ -16,36 +17,37 @@
createhome: false

- name: Get nginx_exporter binary to local folder
get_url:
ansible.builtin.get_url:
url: "{{ nginx_exporter_download_url }}"
dest: "/tmp/nginx_exporter-{{ nginx_exporter_version }}.linux-{{ go_arch }}.tar.gz"
register: __download_binary
until: __download_binary is succeeded
retries: 5
delay: 2
delegate_to: localhost
check_mode: false

- name: Unpack node_exporter binary
unarchive:
ansible.builtin.unarchive:
src: "/tmp/nginx_exporter-{{ nginx_exporter_version }}.linux-{{ go_arch }}.tar.gz"
dest: "/tmp"
creates: "/tmp/nginx_exporter-{{ nginx_exporter_version }}.linux-{{ go_arch }}/nginx_exporter"
delegate_to: localhost
remote_src: true
check_mode: false
become: false

- name: Create local bin dir
file:
- name: Create /usr/local/bin dir
become: true
ansible.builtin.file:
path: /usr/local/bin
state: directory
mode: 0755

- name: Propagate nginx_exporter binary
copy:
become: true
ansible.builtin.copy:
src: /tmp/nginx-prometheus-exporter
dest: /usr/local/bin/nginx_exporter
mode: 0750
remote_src: true
owner: "{{ nginx_exporter_system_user }}"
group: "{{ nginx_exporter_system_group }}"
notify: restart nginx_exporter
10 changes: 6 additions & 4 deletions tasks/main.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
---
- name: install nginx exporter
ansible.builtin.import_tasks: install.yml

- import_tasks: install.yml

- import_tasks: config.yml
- name: create nginx exporter config
ansible.builtin.import_tasks: config.yml

- name: Ensure nginx_exporter is started and enabled
systemd:
become: true
ansible.builtin.systemd:
name: nginx_exporter
state: started
enabled: true
Expand Down
44 changes: 44 additions & 0 deletions tasks/versioncheck.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
---
# Copyright (c) 2021 L3D <[email protected]>
# this file is released with the MIT license.
# License: https://github.com/roles-ansible/ansible_role_template/blob/main/LICENSE
- name: Create directory for versionscheck
become: true
ansible.builtin.file:
path: '/etc/.ansible-version'
state: directory
mode: 0755
when: submodules_versioncheck|bool

- name: check playbook version
become: true
ansible.builtin.slurp:
src: "/etc/.ansible-version/{{ playbook_version_path }}"
register: playbook_version
when: submodules_versioncheck|bool
ignore_errors: true
failed_when: false

- name: Print remote role version
ansible.builtin.debug:
msg: "Remote role version: {{ playbook_version.content | default('Y3VycmVudGx5IG5vdCBkZXBsb3llZAo=') | b64decode | string }}"
when: submodules_versioncheck|bool

- name: Print locale role version
ansible.builtin.debug:
msg: "Local role version: '{{ playbook_version_number|string }}'."
when: submodules_versioncheck|bool

- name: Check if your version is outdated
ansible.builtin.fail:
msg: "Your ansible module has the version '{{ playbook_version_number }}' and is outdated. You need to update it!"
when:
- playbook_version.content|default("Mgo=")|b64decode|int - 1 >= playbook_version_number|int and submodules_versioncheck|bool

- name: write new version to remote disk
become: true
ansible.builtin.copy:
content: "{{ playbook_version_number }}"
dest: "/etc/.ansible-version/{{ playbook_version_path }}"
mode: '0644'
when: submodules_versioncheck|bool
3 changes: 3 additions & 0 deletions vars/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,6 @@ go_arch_map:
x86_64: 'amd64'

go_arch: "{{ go_arch_map[ansible_architecture] | default(ansible_architecture) }}"

playbook_version_number: 6
playbook_version_path: 'do1jlr.nginx_exporter.version'