diff --git a/aya01.yml b/aya01.yml index 910b5e4..a2bd41e 100644 --- a/aya01.yml +++ b/aya01.yml @@ -18,9 +18,12 @@ - role: node_exporter tags: - node_exporter - - role: docker - tags: - - docker - role: snmp_exporter tags: - snmp_exporter + - role: smart_exporter + tags: + - smart_exporter + - role: docker + tags: + - docker diff --git a/group_vars/all/vars.yml b/group_vars/all/vars.yml index bd01571..699b3de 100644 --- a/group_vars/all/vars.yml +++ b/group_vars/all/vars.yml @@ -15,6 +15,20 @@ remote_subdomains: "www,plex,status,tautulli" backup_domain: seyshiro.de backup_subdomains: "hass,qbit,zm," + +# +# Used to download for git releases +# + +go_arch_map: + i386: '386' + x86_64: 'amd64' + aarch64: 'arm64' + armv7l: 'armv7' + armv6l: 'armv6' + +go_arch: "{{ go_arch_map[ansible_architecture] | default(ansible_architecture) }}" + # # aya01 - Disks # @@ -398,7 +412,7 @@ grafana_data: "{{docker_data_dir}}/grafana/" grafana_config: "{{docker_dir}}/grafana/config/" grafana_logs: "{{docker_dir}}/grafana/logs/" grafana_puid: "472" -grafana_pgid: "0" +grafana_pgid: "472" # # SNMP Exporter @@ -429,6 +443,12 @@ gitlab: http: local: 80 remote: 8084 - https: - local: 443 - remote: 8444 + +# +# SMART Exporter +# +smart_exporter: + port: 9633 + version: 'latest' + options: '--web.listen-address=9633' + bin_path: /usr/local/bin/smart_exporter diff --git a/roles/docker/tasks/main.yml b/roles/docker/tasks/main.yml index 42aa5f8..0600542 100644 --- a/roles/docker/tasks/main.yml +++ b/roles/docker/tasks/main.yml @@ -13,12 +13,12 @@ tags: - reload_compose -- name: Update Docker Images +- name: Update docker Images shell: cmd: "docker compose pull" chdir: "{{ docker_compose_dir }}" -- name: Restart Docker +- name: Rebuilding docker images shell: cmd: "docker compose up -d --build" chdir: "{{ docker_compose_dir }}" diff --git a/roles/docker/templates/aya01/compose.yaml b/roles/docker/templates/aya01/compose.yaml index 95634c1..320b16f 100644 --- a/roles/docker/templates/aya01/compose.yaml +++ b/roles/docker/templates/aya01/compose.yaml @@ -456,6 +456,7 @@ services: image: grafana/grafana-oss container_name: {{ grafana_host }} restart: unless-stopped + user: "0:0" depends_on: - {{ prometheus_host }} networks: @@ -491,7 +492,7 @@ services: ports: - {{ gitlab.ports.ssh.remote }}:{{ gitlab.ports.ssh.local }} - {{ gitlab.ports.http.remote }}:{{ gitlab.ports.http.local }} - - {{ gitlab.ports.https.remote }}:{{ gitlab.ports.https.local }} + shm_size: '256m' labels: - "traefik.enable=true" - "traefik.http.routers.{{ gitlab.host }}.rule=Host(`{{ gitlab.host }}.{{ aya01_host }}.{{ local_domain }}`)" diff --git a/roles/docker/templates/aya01/prometheus/prometheus.yml.j2 b/roles/docker/templates/aya01/prometheus/prometheus.yml.j2 index 49eacec..36bd70a 100644 --- a/roles/docker/templates/aya01/prometheus/prometheus.yml.j2 +++ b/roles/docker/templates/aya01/prometheus/prometheus.yml.j2 @@ -39,3 +39,6 @@ scrape_configs: target_label: instance - target_label: __address__ replacement: {{ aya01_ip }}:{{ snmp_exporter_port }} # The SNMP exporter's real hostname:port. + - job_name: 'smart' + static_configs: + - targets: ['{{ aya01_ip }}:{{smart_exporter.port}}'] diff --git a/roles/node_exporter/vars/main.yml b/roles/node_exporter/vars/main.yml deleted file mode 100644 index 87a308a..0000000 --- a/roles/node_exporter/vars/main.yml +++ /dev/null @@ -1,8 +0,0 @@ -go_arch_map: - i386: '386' - x86_64: 'amd64' - aarch64: 'arm64' - armv7l: 'armv7' - armv6l: 'armv6' - -go_arch: "{{ go_arch_map[ansible_architecture] | default(ansible_architecture) }}" diff --git a/roles/smart_exporter/tasks/get_version.yml b/roles/smart_exporter/tasks/get_version.yml new file mode 100644 index 0000000..bcba2fa --- /dev/null +++ b/roles/smart_exporter/tasks/get_version.yml @@ -0,0 +1,18 @@ +--- +- name: Determine latest GitHub release (local) + delegate_to: localhost + uri: + url: "https://api.github.com/repos/prometheus-community/smartctl_exporter/releases/{{ smart_exporter.version }}" + body_format: json + register: _github_release + until: _github_release.status == 200 + retries: 3 + +- name: Set smart_exporter_version + set_fact: + smart_exporter_version: "{{ _github_release.json.tag_name + | regex_replace('^v?([0-9\\.]+)$', '\\1') }}" + +- name: Set smart_exporter_download_url + set_fact: + smart_exporter_download_url: "https://github.com/prometheus-community/smartctl_exporter/releases/download/v{{ smart_exporter_version }}/smartctl_exporter-{{ smart_exporter_version }}.linux-{{ go_arch }}.tar.gz" diff --git a/roles/smart_exporter/tasks/install.yml b/roles/smart_exporter/tasks/install.yml new file mode 100644 index 0000000..1caabce --- /dev/null +++ b/roles/smart_exporter/tasks/install.yml @@ -0,0 +1,30 @@ +--- +- name: Download/Extract "{{ smart_exporter_download_url }}" + unarchive: + src: "{{ smart_exporter_download_url }}" + dest: /tmp/ + remote_src: true + mode: 755 + +- name: Move smart_exporter into path + copy: + src: "/tmp/smartctl_exporter-{{ smart_exporter_version }}.linux-{{ go_arch }}/smartctl_exporter" + dest: "{{ smart_exporter.bin_path }}" + mode: 755 + remote_src: true + become: true + +- name: Create smart_exporter user. + user: + name: smart_exporter + shell: /sbin/nologin + state: present + become: true + +- name: Copy the smart_exporter systemd unit file. + template: + src: smart_exporter.service.j2 + dest: /etc/systemd/system/smart_exporter.service + mode: 0644 + register: smart_exporter_service + become: true diff --git a/roles/smart_exporter/tasks/main.yml b/roles/smart_exporter/tasks/main.yml new file mode 100644 index 0000000..984119d --- /dev/null +++ b/roles/smart_exporter/tasks/main.yml @@ -0,0 +1,4 @@ +--- +- include_tasks: get_version.yml +- include_tasks: install.yml +- include_tasks: systemd.yml diff --git a/roles/smart_exporter/tasks/systemd.yml b/roles/smart_exporter/tasks/systemd.yml new file mode 100644 index 0000000..5a7496e --- /dev/null +++ b/roles/smart_exporter/tasks/systemd.yml @@ -0,0 +1,9 @@ +--- +- name: Ensure smart_exporter is running and enabled at boot. + service: + daemon_reload: true + name: smart_exporter + state: restarted + enabled: true + when: smart_exporter_service is changed + become: true diff --git a/roles/smart_exporter/templates/smart_exporter.service.j2 b/roles/smart_exporter/templates/smart_exporter.service.j2 new file mode 100644 index 0000000..0670745 --- /dev/null +++ b/roles/smart_exporter/templates/smart_exporter.service.j2 @@ -0,0 +1,19 @@ +[Unit] +Description=smartctl exporter service +After=network-online.target + +[Service] +Type=simple +PIDFile=/run/smartctl_exporter.pid +ExecStart={{ smart_exporter.bin_path }} +User=root +Group=root +SyslogIdentifier=smartctl_exporter +Restart=on-failure +RemainAfterExit=no +RestartSec=100ms +StandardOutput=journal +StandardError=journal + +[Install] +WantedBy=multi-user.target