DEV Community

Cover image for Actionable output from Ansible 2.11
Keith Maxwell
Keith Maxwell

Posted on

Actionable output from Ansible 2.11

    ansible-playbook -i, site.yaml

Though there is more to say than that. This is my first blog on and I've ideas and drafts for many more. I was really encouraged by Miguel Grinberg's talk at PyCon Limerick. I am pleased to have put a post out into the world.

I am a big fan of Ansible and have found the community, especially the documentation team, very welcoming. I've been using Ansible since around version 2.4 which was released in 2017. The current version is 2.9.

Ansible 2.7 deprecated a feature for limiting the output of the ansible-playbook command line interface (CLI). It is scheduled to be removed in 2.11. This post explains a little context and how to switch over to the new approach.

As you may know, deprecation is a process for removing features from software; in Ansible deprecation follows a policy. This process gives users warnings and an opportunity to move away from the deprecated feature before anything relying on it breaks.

Simplifying a little, an Ansible playbook runs a series of tasks against a host. By default the ansible-playbook CLI reports back the status from each task. This can be reported as:

  1. OK: completed successfully and nothing was changed
  2. Changed: completed successfully with changes
  3. Failed: the task did not complete . Skipped: the task was not run, likely because of a when: clause

Ansible will report a task as unreachable if it cannot contact the host. Further ignored and rescued relate to bespoke error handling.

Quickly identifying tasks with a changed status is a helpful filter. It is particularly effective if you write idempotent playbooks. Failed tasks are also of interest.

If you are tracking configuration as code, for example as Ansible playbooks in a git repository, this filtering makes it easier to marry the system changes reported by Ansible and the configuration changes in git.

Before Ansible 2.7 the recommended way to filter output to only show tasks with a changed or failed status was the actionable plugin. In Ansible 2.11 that plugin will be removed.

The current approach is to set two options and use the default output plugin. The two commands below show the old and new approach:

ANSIBLE_STDOUT_CALLBACK=actionable ansible-playbook -i, site.yaml
    ansible-playbook -i, site.yaml

There are many different ways to set these options; either in configuration files or environment variables. The change is the same regardless: instead of overriding the default callback plugin for standard out, stdout_callback=actionable, instead set two options on the default callback: display_skipped_hosts=no and display_ok_hosts=no.

For more detail about the background to this change, take a look at the GitHub pull request and commit implementing the deprecation.

Discussion (0)