--- - name: "[Alpine] Install package: node-exporter" apk: name: prometheus-node-exporter state: present update_cache: yes when: - ansible_distribution == "Alpine" - services.prometheus_node_exporter.enable is true notify: Restart prometheus-node-exporter - name: "[Archlinux] Install package: prometheus-node-exporter" pacman: name: prometheus-node-exporter state: present update_cache: yes when: - ansible_distribution == "Archlinux" - services.prometheus_node_exporter.enable is true notify: Restart prometheus-node-exporter - name: "[OpenRC] Enable and start service: node-exporter" service: name: node-exporter enabled: yes state: started when: - ansible_service_mgr == "openrc" - services.prometheus_node_exporter is true - name: "[systemd] Enable and start service: prometheus-node-exporter" systemd: name: prometheus-node-exporter state: started enabled: yes when: - ansible_service_mgr == "systemd" - services.prometheus_node_exporter.enable is true - name: "[OpenRC] Disable and stop service: node-exporter" service: name: node-exporter enabled: no state: stopped when: - ansible_service_mgr == "openrc" - services.prometheus_node_exporter is false - name: "[systemd] Disable and stop service: prometheus-node-exporter" systemd: name: prometheus-node-exporter state: stopped enabled: no when: - services.prometheus_node_exporter.enable is false - ansible_service_mgr == "systemd" - name: "[Alpine] Remove package: node-exporter" apk: name: prometheus-node-exporter state: absent when: - ansible_distribution == "Alpine" - services.prometheus_node_exporter.enable is false - name: "[Archlinux] Remove package: prometheus-node-exporter" pacman: name: prometheus-node-exporter state: absent when: - ansible_distribution == "Archlinux" - services.prometheus_node_exporter.enable is false