Formatting the output by line by line

41 views
Skip to first unread message

Veera

unread,
Aug 28, 2023, 4:56:36 AM8/28/23
to Ansible Project
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.. 

dulh...@mailbox.org

unread,
Aug 28, 2023, 5:17:42 AM8/28/23
to ansible...@googlegroups.com
wondering whether stdout_callback: yaml in the ansible.cfg might be doing that
--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/f7b49add-d473-4e08-9527-e3ed864ca825n%40googlegroups.com.
 
---

gunnar wagner | fichtestr. 1, 19386 lübz | fon: 0176 7808 9090

Veera

unread,
Aug 28, 2023, 5:22:26 AM8/28/23
to Ansible Project
Hi ,

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

dulh...@mailbox.org

unread,
Aug 28, 2023, 5:29:06 AM8/28/23
to ansible...@googlegroups.com
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?
 

Veera

unread,
Aug 28, 2023, 7:11:52 AM8/28/23
to Ansible Project
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
$

dulh...@mailbox.org

unread,
Aug 28, 2023, 7:20:07 AM8/28/23
to ansible...@googlegroups.com
so, my suggestion was to add
 
stdout_callback = yaml to the [defaults] section of that file and see whether the output suits you better.
 
 
--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
Message has been deleted
Message has been deleted

Todd Lewis

unread,
Aug 29, 2023, 10:17:31 AM8/29/23
to ansible...@googlegroups.com, uto...@gmail.com
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.
--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.

Veera

unread,
Aug 29, 2023, 10:34:50 AM8/29/23
to ansible...@googlegroups.com, Todd Lewis
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 .. 

You received this message because you are subscribed to a topic in the Google Groups "Ansible Project" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/ansible-project/ZqZuw3do-5g/unsubscribe.
To unsubscribe from this group and all its topics, send an email to ansible-proje...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/584f136d-c317-79c3-e1d4-56a02781b743%40gmail.com.
Reply all
Reply to author
Forward
0 new messages