Visualise where time is spent in your Ansible playbooks: what tasks, and what hosts, so you can find where to optimise and decrease playbook latency.
An Ansible Callback Function which traces the execution time of Ansible playooks, outputting Chrome's Trace Event Format for visualising in the Perfetto in-browser trace UI.
Here's a trace of me deploying to my home Raspberry Pi cluster, with the default strategy: linear
. You can see that now all the tasks are synchronized across hosts, with each host waiting for the slowest host before proceeding to the next task:
Here's the same playbook ran with strategy: free
so fast hosts run to completion without waiting for slow hosts:
You can click on tasks to see details about them:
- Download (Right-click -> Save Link As) example-trace.json.
- Open https://ui.perfetto.dev/, and drag and drop in the downloaded example-trace.json.
-
Install with Ansible-Galaxy:
ansible-galaxy collection install mhansen.ansible_trace
-
Enable the
mhansen.ansible_trace.trace
callback plugin in youransible.cfg
:[defaults] callbacks_enabled = mhansen.ansible_trace.trace
Or, enable it at the top of your playbook yml:
ansible: env: CALLBACKS_ENABLED: mhansen.ansible_trace.trace TRACE_OUTPUT_DIR: ./trace TRACE_HIDE_TASK_ARGUMENTS: True
-
Run your Ansible Playbook:
$ ansible-playbook site.yml
This will output
trace-<timestamp>.json
in theTRACE_OUTPUT_DIR
(by default:./trace/
). -
Open https://ui.perfetto.dev/, and drag-and-drop in the
trace-<timestamp>.json
.You don't have to wait for the trace to finish; you can open in-progress trace files.
Perfetto is the most mature trace viewer, but here are some other options:
- chrome://tracing (aka Catapult Trace Viewer) is the older version of Perfetto. Supports generating a standalone HTML page.
- Speedscope can open the traces, but only shows one host at a time.
- Firefox Profiler can open the traces, showing trace spans in the "Marker Chart" tab: example.
ansible.posix.profile_tasks
displays task timing as console output, but can't visualise gaps in the timing (e.g. with strategy: linear
when fast hosts wait for slow hosts).
Adding extra v
s adds more debug info, -vvvv
enables connection debugging.
community.general
contains many callback plugins for logging task events to various outputs,
including Azure Log Analyics, LogDNA, Logentries, Logstash, Nagios,
OpenTelemetry, Splunk, Sumologic, and Syslog.
Mitogen promises to speed up your Ansible playbooks with a persistent interpreter. They profile their runs for bandwidth an time by analysing network packet captures.
You need to install from HEAD to support latest Ansible versions, because there hasn't been a tagged release since 2019.