# Formatting the  output  by line by line

**URL:** <https://forum.ansible.com/t/formatting-the-output-by-line-by-line/38380>\
**Category:** Ansible Project\
**Created:** [August 28, 2023, 8:56am UTC](https://forum.ansible.com/t/formatting-the-output-by-line-by-line/38380 "2023-08-28T08:56:36Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Veera](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/veera/32/4107_2.png) [@Veera](https://forum.ansible.com/u/Veera)\
**Post date:** [August 28, 2023, 8:56am UTC](https://forum.ansible.com/t/formatting-the-output-by-line-by-line/38380/1 "2023-08-28T08:56:36Z")

</div>

Hi,

My play book print the debug output as below

TASK [Print the status of the server] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
ok: [localhost] =\> {  
“msg”: [  
“Extension Message: Patching Successful. [ActivityId=xxxxxxx-1f8f-4e44-95af-xxxxxxxxxxxx], OperationResult: {"activityId": "xxxxxxx-1f8f-4e44-95af-xxxxxxxxxxxx", "sequenceNumber": 8, "inputStartTime": "2023-08-28T05:45:40.500520Z", "lastModifiedTime": "2023-08-28T06:14:43.449672Z", "extensionTriggerTime": "2023-08-28T05:45:53.268037Z", "osName": "CentOS Stream", "osVersion": "8", "action": "Patching", "actionStatus": "Success", "patchServiceUsed": "YUM", "errors": null, "patchDetails": {"rebootNeeded": true, "rebootStatus": "Completed", "maintenanceWindowExceeded": false, "retriggerCount": 61, "notSelectedPatchCount": 0, "pendingPatchCount": 0, "installedPatchCount": 98, "failedPatchCount": 0, "patches": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx=", "excludedPatchCount": 0}, "assessmentDetails": {"countByCategory": {"security": 0, "other": 0}, "totalCount": 0, "patches": "XXXXXXXXXXXXX==", "rebootPending": null}, "logs": "yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy”}"  
]  
}

I need to break the output like below

Extension Message: Patching Successful. [ActivityId=xxxxxxx-1f8f-4e44-95af-xxxxxxxxxxxx]  
OperationResult: activityId: xxxxxxx-1f8f-4e44-95af-xxxxxxxxxxxx  
sequenceNumber: 8  
inputStartTime: 2023-08-28T05:45:40.500520Z  
lastModifiedTime: "2023-08-28T06:14:43.449672Z

and so on…

---

<div class="post-metadata">

**Author:** ![dulhaver](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/dulhaver/32/1061_2.png) [@dulhaver](https://forum.ansible.com/u/dulhaver)\
**Post date:** [August 28, 2023, 9:17am UTC](https://forum.ansible.com/t/formatting-the-output-by-line-by-line/38380/2 "2023-08-28T09:17:21Z")

</div>

wondering whether **stdout\_callback: yaml** in the **ansible.cfg** might be doing that

---

<div class="post-metadata">

**Author:** ![Veera](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/veera/32/4107_2.png) [@Veera](https://forum.ansible.com/u/Veera)\
**Post date:** [August 28, 2023, 9:22am UTC](https://forum.ansible.com/t/formatting-the-output-by-line-by-line/38380/3 "2023-08-28T09:22:26Z")

</div>

Hi ,

Sorry … No **ansible.cfg** involved.  
After multiple filtering of (the output) I reached to this output.  
I want to enhance it further .

---

<div class="post-metadata">

**Author:** ![dulhaver](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/dulhaver/32/1061_2.png) [@dulhaver](https://forum.ansible.com/u/dulhaver)\
**Post date:** [August 28, 2023, 9:28am UTC](https://forum.ansible.com/t/formatting-the-output-by-line-by-line/38380/4 "2023-08-28T09:28:44Z")

</div>

**no ansible.cfg involved** seems impossible to me.

ansible --version | grep ‘ansible.cfg’ (in the location you run the playbook from) should reveal which one is effective.

Or am I understanding something badly wrong here?

---

<div class="post-metadata">

**Author:** ![Veera](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/veera/32/4107_2.png) [@Veera](https://forum.ansible.com/u/Veera)\
**Post date:** [August 28, 2023, 11:11am UTC](https://forum.ansible.com/t/formatting-the-output-by-line-by-line/38380/5 "2023-08-28T11:11:52Z")

</div>

my ansible.cfg is a custom one which I am using from the same location and it has no more specific lines to format.

$ansible --version | grep ‘ansible.cfg’  
config file = /home/myuser/ansible/ansible.cfg  
$pwd  
/home/myuser/ansible/  
$ cat ansible.cfg  
[defaults]  
inventory = ./inventory  
host\_key\_checking = False  
$

---

<div class="post-metadata">

**Author:** ![dulhaver](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/dulhaver/32/1061_2.png) [@dulhaver](https://forum.ansible.com/u/dulhaver)\
**Post date:** [August 28, 2023, 11:19am UTC](https://forum.ansible.com/t/formatting-the-output-by-line-by-line/38380/6 "2023-08-28T11:19:43Z")

</div>

so, my suggestion was to add

**stdout\_callback = yaml** to the [defaults] section of that file and see whether the output suits you better.

---

<div class="post-metadata">

**Author:** ![utoddl](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/utoddl/32/249_2.png) [@utoddl](https://forum.ansible.com/u/utoddl)\
**Post date:** [August 29, 2023, 2:17pm UTC](https://forum.ansible.com/t/formatting-the-output-by-line-by-line/38380/7 "2023-08-29T14:17:13Z")

</div>

Could you please back up a step and show the debug task that’s producing this?  
If it’s just a string, then you’ll have to do some sort of pattern matching and replacement operations on that string.  
On the other hand, if it’s a data structure, you can do quite a bit of filtering and templating with Jinja2 to produce the output you seek.  
But without seeing what you’re starting from, there’s no way to make a reasonable suggestion.

---

<div class="post-metadata">

**Author:** ![Veera](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/veera/32/4107_2.png) [@Veera](https://forum.ansible.com/u/Veera)\
**Post date:** [August 29, 2023, 2:34pm UTC](https://forum.ansible.com/t/formatting-the-output-by-line-by-line/38380/8 "2023-08-29T14:34:24Z")

</div>

Yes… My replies went partially uploaded and they did not appeared yesterday.

I tried twice and it seems some glitch.  
Suddenly they appeared. (Not sure about its reported as spam?)

I will share the full details …
