--- - hosts: promclients tasks: - name: Import Node Exporter role import_role: name: prometheus.prometheus.node_exporter when: ansible_service_mgr == "systemd" - name: Install Node Exporter on FreeBSD community.general.pkgng: name: "node_exporter" state: latest when: ansible_service_mgr == "bsdinit" become: true - name: Enable node_exporter service on FreeBSD ansible.builtin.shell: sysrc node_exporter_enable="YES" when: ansible_service_mgr == "bsdinit" register: node_exporter_enable become: true changed_when: '"node_exporter_enable: -> YES" in node_exporter_enable.stdout' - name: Check if node_exporter service is running on FreeBSD ansible.builtin.shell: service node_exporter status when: ansible_service_mgr == "bsdinit" register: node_exporter_running failed_when: '"node_exporter does not exist" in node_exporter_running.stdout' changed_when: false - name: Start node_exporter service on FreeBSD ansible.builtin.shell: service node_exporter start when: - ansible_service_mgr == "bsdinit" - '"node_exporter is not running" in node_exporter_running.stdout' become: true