Home/Templates/Ask every host the same questions
Ask every host the same questions
osquery on Linux, macOS, and Windows, logging changes to accounts, keys, persistence, listening ports, and drivers.
Ansible
Why bother
During an incident the questions are the same on every machine: who can sign in, what starts on its own, what listens on the network, what is running that should not be. Answering them host by host is slow, and the answer from before the incident is usually gone. The template has osquery ask them on a schedule and log what changed, so the history is already there.
Add a local user on a test host. Within an hour the results log shows the user as added.
How it works
Set it up
Pick your platform, then open the level you want. Each level is complete on its own. Read the comments in the files as you go. Anything with a real consequence is explained on the line where it happens.
Ansible. osquery from a checksummed .deb or .rpm, with a scheduled configuration
What you need first
- An inventory, and an account you can become root with.
- The osquery .deb or .rpm URL for your hosts from osquery.io/downloads, and its SHA-256. The templates stop without them.
What it creates
- osqueryd, with flags and a schedule in /etc/osquery
- Questions about users, SSH keys, listening ports, cron, locally added systemd units, kernel modules, and programs running from a deleted file
- Results written to /var/log/osquery and to syslog
- Sudo rules and setuid programs added, questions kept as data, and the configuration checked by osquery before it is used (Standard)
The code
Quick startReady
osquery_package_url: ""playbook.yml, line 27osquery_package_sha256: ""playbook.yml, line 28
ansible all -i inventory.ini -m ping
Proves Ansible can reach every machine before anything changes.ansible-playbook -i inventory.ini playbook.yml --check --diff
Shows each change it would make, line by line. Changes nothing.ansible-playbook -i inventory.ini playbook.yml
Makes the change.ansible-playbook -i inventory.ini playbook.yml
Run it once more. The recap should end with changed=0.
No inventory yet? A one-machine inventory.ini:
[all] web-01 ansible_host=10.0.0.11 ansible_user=ubuntu
Syntax passedAnsible lint passed
Last run 2026-10-02.
Open playbook.yml as plain text
StandardReady
ansible all -i inventory.ini -m ping
Proves Ansible can reach every machine before anything changes.ansible-playbook -i inventory.ini site.yml --check --diff
Shows each change it would make, line by line. Changes nothing.ansible-playbook -i inventory.ini site.yml
Makes the change.ansible-playbook -i inventory.ini site.yml
Run it once more. The recap should end with changed=0.
No inventory yet? A one-machine inventory.ini:
[all] web-01 ansible_host=10.0.0.11 ansible_user=ubuntu
Syntax passedAnsible lint passed
Last run 2026-10-02.
Open main.yml as plain text
Open main.yml as plain text
Open main.yml as plain text
Open main.yml as plain text
Open site.yml as plain text
HardenedReady
ansible all -i inventory.ini -m ping
Proves Ansible can reach every machine before anything changes.ansible-playbook -i inventory.ini site.yml --check --diff
Shows each change it would make, line by line. Changes nothing.ansible-playbook -i inventory.ini site.yml
Makes the change.ansible-playbook -i inventory.ini site.yml
Run it once more. The recap should end with changed=0.
No inventory yet? A one-machine inventory.ini:
[all] web-01 ansible_host=10.0.0.11 ansible_user=ubuntu
Syntax passedAnsible lint passed
Last run 2026-10-02.
Open guard.yml as plain text
Open settings.yml as plain text
Open site.yml as plain text
How to check it worked
osqueryi --json 'select version from osquery_info' answers, and /var/log/osquery/osqueryd.results.log fills as each question first runs.
Each osquery release is a new package, so neither template has a default URL. Pin the version you tested, and change it on purpose.
Questions run first when their interval first passes, so an hourly question logs nothing for up to an hour after install.
How to undo it
Remove the osquery package. The results log stays until you delete /var/log/osquery.
What it costs
Nothing to license. Small CPU cost per question, and a results log that grows with the number of changes.
Ansible. osquery from a checksummed .pkg, run by a launch daemon
What you need first
- Remote Login on for each Mac, and an admin account Ansible signs in as.
- The macOS .pkg URL from osquery.io/downloads, and its SHA-256.
- In a managed fleet, a privacy preferences profile granting osqueryd Full Disk Access, pushed by your device management service.
What it creates
- osquery, installed with the Apple installer, which also checks the package signature
- A launch daemon, io.osquery.agent, reading flags from /var/osquery
- Questions about users, launch items that start at load, system extensions, Gatekeeper, System Integrity Protection, listening ports, and programs running from a deleted file
- Admin group members and configuration profiles added, results also to syslog, and the configuration checked by osquery before it is used (Standard)
The code
Quick startReady
osquery_package_url: ""playbook.yml, line 30osquery_package_sha256: ""playbook.yml, line 31
ansible all -i inventory.ini -m ping
Proves Ansible can reach every machine before anything changes.ansible-playbook -i inventory.ini playbook.yml --check --diff
Shows each change it would make, line by line. Changes nothing.ansible-playbook -i inventory.ini playbook.yml
Makes the change.ansible-playbook -i inventory.ini playbook.yml
Run it once more. The recap should end with changed=0.
No inventory yet? A one-machine inventory.ini. Turn on Remote Login on the Mac first, which is its SSH server.
[all] mac-01 ansible_host=10.0.0.21 ansible_user=admin
Syntax passedAnsible lint passed
Last run 2026-10-02.
Open playbook.yml as plain text
StandardReady
ansible all -i inventory.ini -m ping
Proves Ansible can reach every machine before anything changes.ansible-playbook -i inventory.ini site.yml --check --diff
Shows each change it would make, line by line. Changes nothing.ansible-playbook -i inventory.ini site.yml
Makes the change.ansible-playbook -i inventory.ini site.yml
Run it once more. The recap should end with changed=0.
No inventory yet? A one-machine inventory.ini. Turn on Remote Login on the Mac first, which is its SSH server.
[all] mac-01 ansible_host=10.0.0.21 ansible_user=admin
Syntax passedAnsible lint passed
Last run 2026-10-02.
Open main.yml as plain text
Open main.yml as plain text
Open main.yml as plain text
Open main.yml as plain text
Open io.osquery.agent.plist.j2 as plain text
Open site.yml as plain text
HardenedReady
ansible all -i inventory.ini -m ping
Proves Ansible can reach every machine before anything changes.ansible-playbook -i inventory.ini site.yml --check --diff
Shows each change it would make, line by line. Changes nothing.ansible-playbook -i inventory.ini site.yml
Makes the change.ansible-playbook -i inventory.ini site.yml
Run it once more. The recap should end with changed=0.
No inventory yet? A one-machine inventory.ini. Turn on Remote Login on the Mac first, which is its SSH server.
[all] mac-01 ansible_host=10.0.0.21 ansible_user=admin
Syntax passedAnsible lint passed
Last run 2026-10-02.
Open guard.yml as plain text
Open settings.yml as plain text
Open site.yml as plain text
How to check it worked
osqueryi --json 'select version from osquery_info' answers, and /var/log/osquery/osqueryd.results.log fills.
Without Full Disk Access some tables return nothing, silently. Only a profile from device management can grant it; there is no command for it.
The templates write their own launch daemon, so the flag file it reads is the one they manage, whatever the package ships.
How to undo it
launchctl bootout system/io.osquery.agent, delete the plist from /Library/LaunchDaemons, and run the uninstall script osquery ships.
What it costs
Nothing to license.
Ansible. osquery from a checksummed .msi, run as the osqueryd service
What you need first
- Windows Server 2019 or later, reachable by Ansible over WinRM, and the ansible.windows collection.
- The Windows .msi URL from osquery.io/downloads, and its SHA-256.
What it creates
- The osqueryd service, pointed at a flag file the template manages
- Questions about local users and administrators, scheduled tasks, automatic services, autostart entries, WMI command consumers, unsigned drivers, and listening ports
- BitLocker status added, the configuration checked by osquery before it goes live, and a read-back of the service command line (Standard)
The code
Quick startReady
osquery_msi_url: ""playbook.yml, line 28osquery_msi_sha256: ""playbook.yml, line 29
ansible-galaxy collection install ansible.windows:==3.3.0
Installs the Windows modules, at the version the checks ran against.ansible all -i inventory.ini -m ansible.windows.win_ping
Proves Ansible can reach every machine before anything changes.ansible-playbook -i inventory.ini playbook.yml --check --diff
Shows each change it would make, line by line. Changes nothing.ansible-playbook -i inventory.ini playbook.yml
Makes the change.ansible-playbook -i inventory.ini playbook.yml
Run it once more. The recap should end with changed=0.
No inventory yet? An inventory.ini for machines in an Active Directory domain. Kerberos needs pywinrm with its Kerberos extra on the machine running Ansible.
[windows] app-01.corp.example.com [windows:vars] ansible_connection=winrm ansible_winrm_transport=kerberos ansible_port=5985
Syntax failedAnsible lint failed
Last run 2026-10-02.
Open playbook.yml as plain text
StandardReady
ansible-galaxy collection install -r requirements.yml
Installs the Windows modules, at the version the checks ran against.ansible all -i inventory.ini -m ansible.windows.win_ping
Proves Ansible can reach every machine before anything changes.ansible-playbook -i inventory.ini site.yml --check --diff
Shows each change it would make, line by line. Changes nothing.ansible-playbook -i inventory.ini site.yml
Makes the change.ansible-playbook -i inventory.ini site.yml
Run it once more. The recap should end with changed=0.
No inventory yet? An inventory.ini for machines in an Active Directory domain. Kerberos needs pywinrm with its Kerberos extra on the machine running Ansible.
[windows] app-01.corp.example.com [windows:vars] ansible_connection=winrm ansible_winrm_transport=kerberos ansible_port=5985
Syntax failedAnsible lint failed
Last run 2026-10-02.
Open requirements.yml as plain text
Open main.yml as plain text
Open main.yml as plain text
Open main.yml as plain text
Open main.yml as plain text
Open site.yml as plain text
HardenedReady
ansible-galaxy collection install ansible.windows:==3.3.0
Installs the Windows modules, at the version the checks ran against.ansible all -i inventory.ini -m ansible.windows.win_ping
Proves Ansible can reach every machine before anything changes.ansible-playbook -i inventory.ini site.yml --check --diff
Shows each change it would make, line by line. Changes nothing.ansible-playbook -i inventory.ini site.yml
Makes the change.ansible-playbook -i inventory.ini site.yml
Run it once more. The recap should end with changed=0.
No inventory yet? An inventory.ini for machines in an Active Directory domain. Kerberos needs pywinrm with its Kerberos extra on the machine running Ansible.
[windows] app-01.corp.example.com [windows:vars] ansible_connection=winrm ansible_winrm_transport=kerberos ansible_port=5985
Syntax failedAnsible lint passed
Last run 2026-10-02.
Open guard.yml as plain text
Open settings.yml as plain text
Open site.yml as plain text
How to check it worked
Get-Service osqueryd shows Running, and the results log under C:\Program Files\osquery\log fills.
The templates set the service's command line to read their flag file, so the flags in use do not depend on how the installer set it up. A reinstall can change it back, and the next run fixes it.
Results go to a file. Collect it with your SIEM agent, or set up osquery's Windows event log plugin where its provider is registered.
How to undo it
Uninstall osquery from Apps or with msiexec /x. The log folder stays until you delete it.
What it costs
Nothing to license.
Good to know
- Results are differences. A new SSH key, a new scheduled task, or a new listening port appears as one added row, which is easy to alert on.
- osqueryi on the host answers the same questions on demand, which is how a responder checks one machine during triage.