Ansible: Human-Readable Output Format

By default Ansible sends output of the plays, tasks and module arguments to STDOUT in the format that is not suitable for human reading.

Starting from Ansible 2.5, the default output format can be changed to a human-readable using the callback plugin.

This short note shows how to change the default Ansible’s JSON output format to the more human-friendly YAML format.

Cool Tip: Enable DEBUG mode and increase VERBOSITY in Ansible! Read more →

Ansible Output Format

To change the Ansible’s output format you can pass the ANSIBLE_STDOUT_CALLBACK=yaml environment variable on the command line or define the stdout_callback = yaml in Ansible configuration file.

Run a playbook and get the output in the human-readable format:

$ ANSIBLE_STDOUT_CALLBACK=yaml ansible-playbook playbook.yml

You can also define the stdout_callback = yaml in ansible.cfg:

[defaults]
# Human-readable output
stdout_callback = yaml

Cool Tip: Ansible Playbook – Print Variable & List All Variables! Read more →

One Reply to “Ansible: Human-Readable Output Format”

  1. You can also use a more friendly debug format, rather than the traditional debug.

    I could get it creating the below include:

    #special_debug.yml
    - name:
      debug:
        msg:
        - "{% for _ in range(0,Banner.size-(Banner.title|default('')|length)) %}{% if _ == ((Banner.size-(Banner.title|default('')|length))/2) | round %}{{ Banner.title |default('') }}{% else %}-{% endif %}{% endfor %}"
        - "{% for _ in range(0,Banner.size-(Banner.phrase1|default('')|length)) %}{% if _ == ((Banner.size-(Banner.phrase1|default('')|length))/2) | round %}{{ Banner.phrase1 |default('') }}{% else %} {% endif %}{% endfor %}"
        - "{% for _ in range(0,Banner.size-(Banner.phrase2|default('')|length)) %}{% if _ == ((Banner.size-(Banner.phrase2|default('')|length))/2) | round %}{{ Banner.phrase2 |default('') }}{% else %} {% endif %}{% endfor %}"
        - "{% for _ in range(0,Banner.size-(Banner.phrase3|default('')|length)) %}{% if _ == ((Banner.size-(Banner.phrase3|default('')|length))/2) | round %}{{ Banner.phrase3 |default('') }}{% else %} {% endif %}{% endfor %}"
        - "{% for _ in range(0,Banner.size-(Banner.phrase4|default('')|length)) %}{% if _ == ((Banner.size-(Banner.phrase4|default('')|length))/2) | round %}{{ Banner.phrase4 |default('') }}{% else %} {% endif %}{% endfor %}"
        - "{% for _ in range(0,Banner.size-(Banner.phrase5|default('')|length)) %}{% if _ == ((Banner.size-(Banner.phrase5|default('')|length))/2) | round %}{{ Banner.phrase5 |default('') }}{% else %} {% endif %}{% endfor %}"
        - "{% for _ in range(0,Banner.size-(Banner.footer|default('')|length)) %}{% if _ == ((Banner.size-(Banner.footer|default('')|length))/2) | round %}{{ Banner.footer |default('') }}{% else %}-{% endif %}{% endfor %}"
    
    #main.yml
    tasks:
    - name: DEBUG
      vars:
        Banner:
          Titulo:  "BANNER ANSIBLE"
          phrase1: "This is a banner"
          phrase2: "that centralize content"
          phrase3: "Its cool"
          phrase4: "BYE"
          phrase5: ""
          footer:  "END OF BANNER ANSIBLE"
          size: 80
      include_tasks: special_debug.yml
    
    
    RESULT:
    TASK [BANNER] *******************************************
    ok: [SERVER01] =>
      msg:
      - '----------------------BANNER ANSIBLE-------------------'
      - '                     This is a banner                                          '
      - '                that centralize content                                 '
      - '                       Its cool                                                       '
      - '                          BYE                                                         '
      - '                                                                                          '
      - '------------------END OF BANNER ANSIBLE----------------'
    
    
    

Leave a Reply