Giter Club home page Giter Club logo

ansible-trace's Introduction

ansible-trace

Version on Galaxy

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:

Perfetto window showing tasks all happening synchronized

Here's the same playbook ran with strategy: free so fast hosts run to completion without waiting for slow hosts:

Perfetto window showing durations

You can click on tasks to see details about them:

Perfetto window showing details showing arguments and filename of task

Interactive Example

  1. Download (Right-click -> Save Link As) example-trace.json.
  2. Open https://ui.perfetto.dev/, and drag and drop in the downloaded example-trace.json.

Usage

  1. Install with Ansible-Galaxy:

    ansible-galaxy collection install mhansen.ansible_trace
  2. Enable the mhansen.ansible_trace.trace callback plugin in your ansible.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
  3. Run your Ansible Playbook:

    $ ansible-playbook site.yml

    This will output trace-<timestamp>.json in the TRACE_OUTPUT_DIR (by default: ./trace/).

  4. 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.

Other Trace Viewers

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.

Other Ansible Profiling Tools

profile_tasks

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).

ansible-playbook -vvvv

Adding extra vs adds more debug info, -vvvv enables connection debugging.

Logging and Tracing Plusing in community.general

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 for Ansible

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.

ansible-trace's People

Contributors

mhansen avatar nikaro avatar xisabla avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.