--- - name: Stop if the package or its checksum was not set ansible.builtin.assert: that: - osquery_package_url is match('https://.+\.pkg$') - osquery_package_sha256 | length == 64 fail_msg: Set osquery_package_url to the macOS .pkg, 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: /private/var/tmp/osquery.pkg checksum: "sha256:{{ osquery_package_sha256 }}" mode: "0644" notify: Install the downloaded package # The binary is needed below, to check the configuration before it is used. - name: Install now, if a new package arrived ansible.builtin.meta: flush_handlers - name: Make the log folder ansible.builtin.file: path: "{{ osquery_log_dir }}" state: directory owner: root group: wheel mode: "0750" - name: Write the daemon flags ansible.builtin.copy: dest: /var/osquery/osquery.flags owner: root group: wheel mode: "0640" content: | --config_path=/var/osquery/osquery.conf --logger_plugin={{ osquery_logger_plugins | join(',') }} --logger_path={{ osquery_log_dir }} --disable_events=true notify: Restart osqueryd - name: Write the scheduled questions, checked by osquery first ansible.builtin.copy: dest: /var/osquery/osquery.conf owner: root group: wheel mode: "0640" content: "{{ {'schedule': osquery_queries | combine(osquery_extra_queries)} | to_nice_json }}\n" validate: "{{ osquery_daemon }} --config_check --config_path %s" notify: Restart osqueryd - name: Write the launch daemon ansible.builtin.template: src: io.osquery.agent.plist.j2 dest: /Library/LaunchDaemons/io.osquery.agent.plist owner: root group: wheel mode: "0644" validate: plutil -lint %s notify: Restart osqueryd - name: Check whether the daemon is loaded ansible.builtin.command: launchctl print system/io.osquery.agent register: osquery_loaded changed_when: false failed_when: false - name: Load it if it is not ansible.builtin.command: launchctl bootstrap system /Library/LaunchDaemons/io.osquery.agent.plist when: osquery_loaded.rc != 0 changed_when: true - 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