diff --git a/LICENSE b/LICENSE index 5b410c8..a4a3d3b 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,7 @@ MIT License Copyright (c) 2019 Agnesius Santo Naibaho +Copyright (c) 2021 L3D Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/README.md b/README.md index 3b0b546..d63b391 100644 --- a/README.md +++ b/README.md @@ -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 | | 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))* diff --git a/defaults/main.yml b/defaults/main.yml index e923646..22bb846 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -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 diff --git a/handlers/main.yml b/handlers/main.yml index 3a50854..63eb469 100644 --- a/handlers/main.yml +++ b/handlers/main.yml @@ -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 diff --git a/meta/main.yml b/meta/main.yml index 4fda67e..22d38ea 100644 --- a/meta/main.yml +++ b/meta/main.yml @@ -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 diff --git a/tasks/config.yml b/tasks/config.yml index 69f8961..fccce79 100644 --- a/tasks/config.yml +++ b/tasks/config.yml @@ -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 diff --git a/tasks/install.yml b/tasks/install.yml index b70eef5..b3ba69a 100644 --- a/tasks/install.yml +++ b/tasks/install.yml @@ -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 @@ -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 diff --git a/tasks/main.yml b/tasks/main.yml index a9b8a7d..6431ef3 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -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 diff --git a/tasks/versioncheck.yml b/tasks/versioncheck.yml new file mode 100644 index 0000000..5128cc8 --- /dev/null +++ b/tasks/versioncheck.yml @@ -0,0 +1,44 @@ +--- +# Copyright (c) 2021 L3D +# 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 diff --git a/vars/main.yml b/vars/main.yml index 956ff31..5878f4d 100644 --- a/vars/main.yml +++ b/vars/main.yml @@ -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'