0

Is there any way to sort this Ansible output?

I tried to use regex but still displaying escape character and display the output in the following format.

 - "Description": "\nRequested for Details:\n\nRequested for Name: Maddy
   XYZ\nRequested for Email: abc.def@ghi.com\nRequested for Number:
   12345678\nRequested for Phone: \nRequested for Department:
   EDUCATION\nRequested for User Domain:\n\nRequested by
   Details:\nRequested by Name: Maddy XYZ\nRequested by Email:
   abc.def@ghi.com\\nRequested by Employee Number: 12345678\nRequested
   by Phone: \n\nRequest Details: \nItem: ABC OPERATIONS - Request
   Form\nCode: Services\Code: M1N0\nEnvironment: no\nDescription: 1.
   Result is coming as not pass for every application\n2. additional
   description\nPriority: High\nRequest and Response (XMLs, JSON):
   result is not
   pass\n{\"\":\"NOTFOOUND\",\"\":\"FULL\",\"AlertsEvalResult\":\"FULL\",\"identityAlertsEvalResult\":\"FULL\",\"\":{\"RptScore\":1000,\"numInq\":0,\"RptSourceType\":\"Intrnl\",\"RptMessages\":[{\"seqNum\":0,\"message\":\"No
   File
   (L2)\"}],\"Alerts\":null,\"\":null,\"identityAlerts\":null,\"internalAlerts\":[{\"code\":\"500\",\"description\":\"No
   File\",

How I can display this output in standard format?

Thanks!

U880D
  • 8,601
  • 6
  • 24
  • 40
user312307
  • 153
  • 6
  • 21
  • Does this answer your question? [How to escape backslash and double quote in Ansible (script module)](https://stackoverflow.com/questions/39580797/how-to-escape-backslash-and-double-quote-in-ansible-script-module) – U880D Mar 29 '22 at 04:24
  • 2
    What do you expect? Please don't answer in comments, edit your question. While you're at it, format your pasted output correctly in a code block. Thanks. – Zeitounator Mar 29 '22 at 06:14

1 Answers1

2

I understand your question that you like to display the ansible-playbook output in an other way formatted.

Whereby with a default setting in ansible.cfg of

# stdout_callback         = yaml

a playbook like

---
- hosts: localhost
  become: false
  gather_facts: false

  vars:
    text: |

      This is:
      Some longer example text

      with line breaks.

  tasks:

  - name: Show message
    debug:
      msg: "{{ text }}"

results into an output of

TASK [Show message] ************************************************************************
ok: [localhost] => {
    "msg": "\nThis is:\nSome longer example text\n\nwith line breaks.\n"
}

Setting an other callback plugin

stdout_callback         = yaml

will result into an yaml-ized Ansible screen output output of

TASK [Show message] ********
ok: [localhost] =>
  msg: |2-

    This is:
    Some longer example text

    with line breaks.

Further Documentation

Further Q&A

U880D
  • 8,601
  • 6
  • 24
  • 40
  • 1
    Perfect, thanks. I defined it in ansible.cfg but was not getting applied. later I passed the ansible config from commandl line and it worked :D Thanks. – user312307 Mar 29 '22 at 18:43