--- - name: Stop if the package or its checksum was not set ansible.builtin.assert: that: - osquery_package_url is match('https://.+\.(deb|rpm)$') - osquery_package_sha256 | length == 64 fail_msg: Set osquery_package_url to the .deb or .rpm, and osquery_package_sha256 to its SHA-256. - name: Download osquery, refusing it if the checksum differs ansible.builtin.get_url: url: "{{ osquery_package_url }}" dest: "/var/tmp/{{ osquery_package_url | basename }}" checksum: "sha256:{{ osquery_package_sha256 }}" mode: "0644" - name: Install it (Debian and Ubuntu) ansible.builtin.apt: deb: "/var/tmp/{{ osquery_package_url | basename }}" when: osquery_package_url.endswith('.deb') notify: Restart osqueryd - name: Install it (Red Hat family) ansible.builtin.dnf: name: "/var/tmp/{{ osquery_package_url | basename }}" state: present when: osquery_package_url.endswith('.rpm') notify: Restart osqueryd - name: Make the log folder ansible.builtin.file: path: "{{ osquery_log_dir }}" state: directory owner: root group: root mode: "0750" - name: Write the daemon flags ansible.builtin.copy: dest: /etc/osquery/osquery.flags owner: root group: root mode: "0640" content: | --config_path=/etc/osquery/osquery.conf --logger_plugin={{ osquery_logger_plugins | join(',') }} --logger_path={{ osquery_log_dir }} --disable_events=true notify: Restart osqueryd # osquery reads the file and exits non-zero on a bad query or bad JSON, so a # broken change never replaces a working one. - name: Write the scheduled questions, checked by osquery first ansible.builtin.copy: dest: /etc/osquery/osquery.conf owner: root group: root mode: "0640" content: "{{ {'schedule': osquery_queries | combine(osquery_extra_queries)} | to_nice_json }}\n" validate: osqueryd --config_check --config_path %s notify: Restart osqueryd - name: Make sure osqueryd is enabled and running ansible.builtin.service: name: osqueryd enabled: true state: started - name: Flush handlers so the check below talks to the new configuration ansible.builtin.meta: flush_handlers - name: Ask osquery a question ansible.builtin.command: osqueryi --json "SELECT version FROM osquery_info;" changed_when: false register: osquery_answer when: not ansible_check_mode - name: Show the version answering ansible.builtin.debug: msg: "osquery {{ (osquery_answer.stdout | from_json)[0].version }} is installed and answering." when: not ansible_check_mode