commit f332f22f1a80027ed2518a24484aa9089ed67678 Author: ace Date: Thu Aug 10 17:14:07 2023 +0300 first commit 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..a6f34b7 --- /dev/null +++ b/defaults/main.yaml @@ -0,0 +1,2 @@ +postgres_exporter_version: "0.12.0" +postgres_exporter_install_official_repo: true diff --git a/meta/main.yaml b/meta/main.yaml new file mode 100644 index 0000000..2b872fd --- /dev/null +++ b/meta/main.yaml @@ -0,0 +1,8 @@ +--- +galaxy_info: + description: postgres_exporter + galaxy_tags: + - postgres + - exporter + +dependencies: [] diff --git a/tasks/Debian.yaml b/tasks/Debian.yaml new file mode 100644 index 0000000..b1113e8 --- /dev/null +++ b/tasks/Debian.yaml @@ -0,0 +1,36 @@ +--- +- name: Install apt-transport-https + apt: + name: apt-transport-https + state: present + +- name: Add gpg keys for prometheus repo + ansible.builtin.apt_key: + url: "{{ item.url }}" + keyring: "{{ item.keyring }}" + loop: "{{ postgres_exporter_apt_key }}" + when: + - postgres_exporter_apt_key is defined + - postgres_exporter_install_official_repo + +- name: Add prometheus repository + ansible.builtin.apt_repository: + repo: "{{ item.repo }}" + state: present + filename: "{{ item.filename }}" + update_cache: no + loop: "{{ postgres_exporter_apt_repository }}" + when: postgres_exporter_install_official_repo + +- name: Ensure {{ postgres_exporter_package }} version {{ postgres_exporter_version }} installed + apt: + name: "{{ postgres_exporter_package }}" + state: present + +- name: Enable and start {{ postgres_exporter_unit_name }} + systemd: + name: "{{ postgres_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..e8f4816 --- /dev/null +++ b/tasks/RedHat.yaml @@ -0,0 +1,25 @@ +--- +- name: Install prometheus repository + ansible.builtin.yum_repository: + name: "{{ item.name }}" + description: "{{ item.description }}" + file: "{{ item.file }}" + baseurl: "{{ item.baseurl }}" + gpgcheck: "{{ item.gpgcheck | default('no') }}" + enabled: "{{ item.enabled | default('yes') }}" + repo_gpgcheck: "{{ item.repo_gpgcheck | default('no') }}" + gpgkey: "{{ item.gpgkey | default('omit') }}" + loop: "{{ postgres_exporter_rpm_repository }}" + +- name: Ensure {{ postgres_exporter_package }} version {{ postgres_exporter_version }} installed + dnf: + name: "{{ postgres_exporter_package }}" + state: present + +- name: Enable and start {{ postgres_exporter_unit_name }} + systemd: + name: "{{ postgres_exporter_unit_name }}" + 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..5e916d6 --- /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: postgres_exporter_vars + +- name: Include postgres_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..fb2b667 --- /dev/null +++ b/vars/Debian.yaml @@ -0,0 +1,8 @@ +postgres_exporter_apt_repository: + - repo: deb [trusted=yes] https://mirror.0xace.cc/debian/custom/ default all + filename: mirror.0xace.cc + +postgres_exporter_package_name: "postgres-exporter" +postgres_exporter_package: "{{ postgres_exporter_package_name }}={{ postgres_exporter_version }}-{{ postgres_exporter_version_build }}" +postgres_exporter_version_build: "1" +postgres_exporter_unit_name: "postgres_exporter" diff --git a/vars/RedHat.yaml b/vars/RedHat.yaml new file mode 100644 index 0000000..197b479 --- /dev/null +++ b/vars/RedHat.yaml @@ -0,0 +1,14 @@ +postgres_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 + +postgres_exporter_package_name: "postgres_exporter" +postgres_exporter_package: "{{ postgres_exporter_package_name }}-{{ postgres_exporter_version }}" +postgres_exporter_unit_name: "{{ postgres_exporter_package_name }}"