3

I have the following playbook:

---
- name: Find sudo mit PPID 1
  hosts: solaris
  become: true

  tasks:
    - shell: "pgrep -P1 -x sudo | xargs -n1 ptree"
      register: result
    - debug: var=result.stdout_lines

The command ansible-playbook quotes the standard output of the command in JSON syntax:

ok: [gggggggg] => {
    "result.stdout_lines": [
        "26982 sudo su -", 
        "  26983 -sh", 
        "    6628  zlogin NNNNNNNN", 
        "      6629  -sh"
    ]
}

This is pretty unreadable for me.

Is it possible to write stdout without JSON quoting as it is done by ad-hoc commands?

gggggggg | SUCCESS | rc=0 >>
17589 sudo su -
  17590 -sh
    17613 zlogin NNNNNNNN
      17614 -sh
        17646 bash
ceving
  • 534
  • 4
  • 26

1 Answers1

1

Try using the to_nice_json filter:

tasks:
- shell: "pgrep -P1 -x sudo | xargs -n1 ptree"
  register: result
- debug: var="{{ result.stdout_lines | to_nice_json }}"
Cory
  • 11
  • 1