Have you tried the `to_nice_json` filter?
https://docs.ansible.com/ansible/latest/user_guide/playbooks_filters.html#formatting-data-yaml-and-json

On Wed, Aug 25, 2021 at 8:12 AM Johnnie Green <johnnie.gr...@mail.com>
wrote:

> Not sure if markdown will work as I hope in the post (will post images if
> not) but thought a brief illustration may prove helpful on the default
> formatting achieved via a task using the 'debug' module (*and how
> difficult it is to relate to*) in comparison to if the desired limited
> formatting were easily possible:
>
> *Default **(no effort made in the Playbook to  control formatting but I
> have attempted to break lines in the post to simulate how it would be
> presented on a typical terminal):*
> ><pre>TASK [Display Warning When Any Service Is Found Not Running Where
> Expected After the Relocate Operation]************************
> ok: [core1] => {
>     "msg": "(UNEXPECTED-STATUS)\nThe following represents the status of
> micro services following the 'relocate'
>     operation:\n{'microservice-a': {'previous_host': 'node04',
> 'previous_ip': '192.0.2.4', 'target_host': 'node05',
>     'target_ip': '192.0.2.5', 'actual_ip': '192.0.2.5'}, 'microservice-b':
> {'previous_host': 'node04', 'previous_ip':
>     '192.0.2.4', 'target_host': 'node05', 'target_ip': '192.0.2.5',
> 'actual_ip': '192.0.2.4'}, 'microservice-c':
>     {'previous_host': 'node04', 'previous_ip': '192.0.2.4', 'target_host':
> 'node05', 'target_ip': '192.0.2.5',
>     'actual_ip': '192.0.2.5'}, 'microservice-d': {'previous_host':
> 'node04', 'previous_ip': '192.0.2.4', 'target_host':
>     'node05', 'target_ip': '192.0.2.5', 'actual_ip': '192.0.2.4'}}\nThe
> following micro services are not running where
>     expected:\n{'microservice-b': {'previous_host': 'node04',
> 'previous_ip': '192.0.2.4', 'target_host': 'node05',
>     'target_ip': '192.0.2.5', 'actual_ip': '192.0.2.4'}, 'microservice-d':
> {'previous_host': 'node04', 'previous_ip':
>     '192.0.2.4', 'target_host': 'node05', 'target_ip': '192.0.2.5',
> 'actual_ip': '192.0.2.4'}}\nPlease take manual
>     action to stop the following services at their current location and
> start them at their intended location."
> }</pre>
>
> *Limited formatting **(I have left the line break symbols in for
> easier visualization where the line breaks occurred against the above)**:*
> > <pre>TASK [Display Warning When Any Service Is Found Not Running Where
> Expected After the Relocate Operation] ************************
> ok: [core1] => {
>     "msg": "
>       (UNEXPECTED-STATUS)\n
>       The following represents the status of micro services following the
> 'relocate' operation:\n
>       {
>         'microservice-a': {
>           'previous_host': 'node04',
>           'previous_ip': '192.0.2.4',
>           'target_host': 'node05',
>           'target_ip': '192.0.2.5',
>           'actual_ip': '192.0.2.5'
>         },
>         'microservice-b': {
>           'previous_host': 'node04',
>           'previous_ip': '192.0.2.4',
>           'target_host': 'node05',
>           'target_ip': '192.0.2.5',
>           'actual_ip': '192.0.2.4'
>         },
>         'microservice-c': {
>           'previous_host': 'node04',
>           'previous_ip': '192.0.2.4',
>           'target_host': 'node05',
>           'target_ip': '192.0.2.5',
>           'actual_ip': '192.0.2.5'
>         },
>         'microservice-d': {
>           'previous_host': 'node04',
>           'previous_ip': '192.0.2.4',
>           'target_host': 'node05',
>           'target_ip': '192.0.2.5',
>           'actual_ip': '192.0.2.4'
>         }
>       }\n
>       The following micro services are not running where expected:\n
>       {
>         'microservice-b': {
>           'previous_host': 'node04',
>           'previous_ip': '192.0.2.4',
>           'target_host': 'node05',
>           'target_ip': '192.0.2.5',
>           'actual_ip': '192.0.2.4'
>         },
>         'microservice-d': {
>           'previous_host': 'node04',
>           'previous_ip': '192.0.2.4',
>           'target_host': 'node05',
>           'target_ip': '192.0.2.5',
>           'actual_ip': '192.0.2.4'
>        }
>       }\n
>       Please take manual action to stop the following services at their
> current location and start them at their intended location."
> }</pre>
>
> Surely allowing the developer a little more control over the formatting of
> certain messages is possible/worthwhile?
>
> --
> You received this message because you are subscribed to the Google Groups
> "Ansible Development" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to ansible-devel+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-devel/fa271bfd-f282-4817-b9b0-438c08410802n%40googlegroups.com
> <https://groups.google.com/d/msgid/ansible-devel/fa271bfd-f282-4817-b9b0-438c08410802n%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Development" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to ansible-devel+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-devel/CALF5A-Jghkgcm7_7yrAZjk2EfnLiypKcoeLat9xbX0iLfGTunw%40mail.gmail.com.

Reply via email to