1--- 2- hosts: promclients 3 tasks: 4 - name: Import Node Exporter role 5 import_role: 6 name: prometheus.prometheus.node_exporter 7 when: ansible_service_mgr == "systemd" 8 9 - name: Install Node Exporter on FreeBSD 10 community.general.pkgng: 11 name: "node_exporter" 12 state: latest 13 when: ansible_service_mgr == "bsdinit" 14 become: true 15 16 - name: Enable node_exporter service on FreeBSD 17 ansible.builtin.shell: sysrc node_exporter_enable="YES" 18 when: ansible_service_mgr == "bsdinit" 19 register: node_exporter_enable 20 become: true 21 changed_when: '"node_exporter_enable: -> YES" in node_exporter_enable.stdout' 22 23 - name: Check if node_exporter service is running on FreeBSD 24 ansible.builtin.shell: service node_exporter status 25 when: ansible_service_mgr == "bsdinit" 26 register: node_exporter_running 27 failed_when: '"node_exporter does not exist" in node_exporter_running.stdout' 28 changed_when: false 29 30 - name: Start node_exporter service on FreeBSD 31 ansible.builtin.shell: service node_exporter start 32 when: 33 - ansible_service_mgr == "bsdinit" 34 - '"node_exporter is not running" in node_exporter_running.stdout' 35 become: true