You've successfully subscribed to Nuvotex Blog
Great! Next, complete checkout for full access to Nuvotex Blog
Welcome back! You've successfully signed in.
Success! Your account is fully activated, you now have access to all content.
Success! Your billing info is updated.
Billing info update failed.

Ansible - pretty print output

Sometimes you want to print more or extensive information on ansible output (in this case a terraform plan). This can easily be realised using an stdout callback.

Daniel Nachtrub
Daniel Nachtrub

We're having 2024 and writing about ansible might seem a little dated because terraform is fairly dominant nowadays. And it's true, terraform is meant to work with APIs [and really good in this domain]. The reality is, not everything has an API 😀

One task where i'm working currently with ansible is to create some CICD (gitlab) pipelines that need to either build applications or deploy infrastructure and might even manage dedicated systems or networking equipment. As i'm really not into bash and scripting (due too much state management, typically poor error handling due lack of time, ...) ansible is the way to go.

One simple requirement is: Output should be shown human readable in the logs so that some diffs (or even terraform plans) can be verified before changes go live.

unformatted output

This looks not very nice. I would guess that no one (except neo from the matrix) can read this.

YAML format to the rescue

The solution is fairly easy. You can get ansible to make a pretty print version of the output, this looks like this:

yaml formatted output

How to get this you ask?

Configure using ENV

To change this on the fly, use an ENV

ANSIBLE_STDOUT_CALLBACK=yaml ansible-playbook myplay.yml

output format using env

You can also persist this in the ansible.cfg

[defaults]
...
# set the output plugin
stdout_callback = yaml

[inventory]
enable_plugins = yaml

configuration in ansible.cfg

That's it - quick & simple.

IaCLinuxTerraformCloud

Daniel Nachtrub

Kind of likes computers. Linux foundation certified: LFCS / CKA / CKAD / CKS. Microsoft certified: Cybersecurity Architect Expert & Azure Solutions Architect Expert.