From c3c1c7de0717c1ef2dd40dab329efdd4faa88f5e Mon Sep 17 00:00:00 2001 From: ace Date: Thu, 10 Aug 2023 17:12:28 +0300 Subject: [PATCH] first commit --- README.md | 0 defaults/main.yaml | 2 ++ meta/main.yaml | 8 ++++++++ tasks/Debian.yaml | 20 ++++++++++++++++++++ tasks/RedHat.yaml | 13 +++++++++++++ tasks/main.yaml | 17 +++++++++++++++++ vars/Debian.yaml | 9 +++++++++ vars/RedHat.yaml | 14 ++++++++++++++ 8 files changed, 83 insertions(+) create mode 100644 README.md create mode 100644 defaults/main.yaml create mode 100644 meta/main.yaml create mode 100644 tasks/Debian.yaml create mode 100644 tasks/RedHat.yaml create mode 100644 tasks/main.yaml create mode 100644 vars/Debian.yaml create mode 100644 vars/RedHat.yaml diff --git a/README.md b/README.md new file mode 100644 index 0000000..e69de29 diff --git a/defaults/main.yaml b/defaults/main.yaml new file mode 100644 index 0000000..dab8c9b --- /dev/null +++ b/defaults/main.yaml @@ -0,0 +1,2 @@ +node_exporter_version: "1.5.0" +node_exporter_install_official_repo: true diff --git a/meta/main.yaml b/meta/main.yaml new file mode 100644 index 0000000..f72ac63 --- /dev/null +++ b/meta/main.yaml @@ -0,0 +1,8 @@ +--- +galaxy_info: + description: node_exporter + galaxy_tags: + - node_exporter + - exporter + +dependencies: [] diff --git a/tasks/Debian.yaml b/tasks/Debian.yaml new file mode 100644 index 0000000..a304614 --- /dev/null +++ b/tasks/Debian.yaml @@ -0,0 +1,20 @@ +--- +- name: Add the user 'prometheus' for node_exporter + ansible.builtin.user: + name: prometheus + shell: /usr/sbin/nologin + append: yes + home: /var/lib/prometheus + +- name: Ensure {{ node_exporter_package }} installed + apt: + name: "{{ node_exporter_package }}" + state: present + +- name: Enable and start node_exporter + systemd: + name: "{{ node_exporter_unit_name }}" + state: started + enabled: yes + masked: no + daemon_reload: yes diff --git a/tasks/RedHat.yaml b/tasks/RedHat.yaml new file mode 100644 index 0000000..8613b40 --- /dev/null +++ b/tasks/RedHat.yaml @@ -0,0 +1,13 @@ +--- +- name: Ensure node_exporter version {{ node_exporter_version }} installed + dnf: + name: "node_exporter-{{ node_exporter_version }}" + state: present + +- name: Enable and start node_exporter + systemd: + name: node_exporter + state: started + enabled: yes + masked: no + daemon_reload: yes diff --git a/tasks/main.yaml b/tasks/main.yaml new file mode 100644 index 0000000..505639f --- /dev/null +++ b/tasks/main.yaml @@ -0,0 +1,17 @@ +--- +- name: Load a variable file based on the OS type + include_vars: "{{ lookup('first_found', params) }}" + vars: + params: + files: + - "{{ ansible_facts['distribution'] }}-{{ ansible_facts['distribution_major_version'] }}.yaml" + - "{{ ansible_facts['distribution'] }}-{{ ansible_facts['distribution_version'] }}.yaml" + - "{{ ansible_facts['os_family'] }}-{{ ansible_facts['distribution_major_version'] }}.yaml" + - "{{ ansible_facts['os_family'] }}-{{ ansible_facts['distribution_version'] }}.yaml" + - "{{ ansible_facts['os_family'] }}.yaml" + paths: + - "vars" + tags: node_exporter_vars + +- name: Include node_exporter install + include_tasks: "{{ ansible_facts['os_family'] }}.yaml" diff --git a/vars/Debian.yaml b/vars/Debian.yaml new file mode 100644 index 0000000..e57a975 --- /dev/null +++ b/vars/Debian.yaml @@ -0,0 +1,9 @@ +node_exporter_apt_repository: + - repo: deb [trusted=yes] https://mirror.0xace.cc/debian/custom/ default all + filename: mirror.0xace.cc + +node_exporter_package_name: "node-exporter" +node_exporter_package: "{{ node_exporter_package_name }}={{ node_exporter_version }}-{{ node_exporter_version_build }}" +node_exporter_version_build: "1" +node_exporter_unit_name: "node_exporter" + diff --git a/vars/RedHat.yaml b/vars/RedHat.yaml new file mode 100644 index 0000000..7b231ae --- /dev/null +++ b/vars/RedHat.yaml @@ -0,0 +1,14 @@ +node_exporter_rpm_repository: + - name: "prometheus" + file: "prometheus" + description: "Prometheus repository" + baseurl: "https://packagecloud.io/prometheus-rpm/release/el/$releasever/$basearch" + repo_gpgcheck: yes + gpgcheck: yes + gpgkey: >- + https://packagecloud.io/prometheus-rpm/release/gpgkey + https://raw.githubusercontent.com/lest/prometheus-rpm/master/RPM-GPG-KEY-prometheus-rpm + +node_exporter_package_name: "node_exporter" +node_exporter_package: "{{ node_exporter_package_name }}-{{ node_exporter_version }}" +node_exporter_unit_name: "{{ node_exporter_package_name }}"