How to convert o/p of ansible playbook to a proper readable format

Hi ,

I have a role for deleting VM using PWSH script via ansible :

Hi ,

I have a role for deleting VM using PWSH script via ansible :
---
- name: Run PowerShellGet VM script
delegate_to: localhost
shell: pwsh /home/raka/delete-snapshot{{item}}.ps1
ignore_errors: yes
changed_when: false
register: powershell_VM_snapshot_delete
with_items: "{{ inventory_hostname }}"

- debug:
# msg: "{{ item.stdout_lines }}"
msg: "{{ powershell_VM_snapshot_delete }}"
# loop: "{{ powershell_VM_snapshot_delete.results }}"
~

Add the following to your ansible.cfg (under [defaults]).

# Use the YAML callback plugin.
stdout_callback = yaml

# Use the stdout_callback when running ad-hoc commands.
bin_ansible_callbacks = True

You can also try the debug callback plugin.

Regards
         Racke

Hi Racke,
Thanks for your suggestion
I have modified as per your instructions and used the callback plugins, It just formatted the lines to a compact form but still somewhat not readable. Is there any way to present teh o/p in more refined way

stdout: ’ Remove snapshot percent complete: 0 Remove snapshot percent complete: 0 Remove
snapshot percent complete: 0 Remove snapshot percent complete: 0 Remove snapshot percent complete: 0 Remove
snapshot percent complete: 0 Remove snapshot percent complete: 0 Remove snapshot percent complete: 0 Remove
snapshot percent complete: 0 Remove snapshot percent complete: 0 Remove snapshot percent complete: 0 Remove
snapshot percent complete: 0 Remove snapshot percent complete: 0 Remove snapshot percent complete: 0 Remove
snapshot percent complete: 0 Remove snapshot percent complete: 0 Remove snapshot percent complete: 0 Remove
snapshot percent complete: 0 Remove snapshot percent complete: 0 Remove snapshot percent complete: 0 Remove
snapshot percent complete: 0 Remove snapshot percent complete: 0 Remove snapshot percent complete: 0 Remove
snapshot percent complete: 0 Remove snapshot percent complete: 0 Remove snapshot percent complete: 0 Remove
snapshot percent complete: 0 Remove snapshot percent complete: 0 Remove snapshot percent complete: 0 Remove
snapshot percent complete: 0 Remove snapshot percent complete: 0 Remove snapshot percent complete: 0 Remove
snapshot percent complete: 0 Remove snapshot percent complete: 0
stdout_lines:

  • ’ Remove snapshot percent complete: 0 Remove snapshot percent complete: 0 Remove
    snapshot percent complete: 0 Remove snapshot percent complete: 0 Remove snapshot percent complete: 0 Remove
    snapshot percent complete: 0 Remove snapshot percent complete: 0 Remove snapshot percent complete: 0 Remove
    snapshot percent complete: 0 Remove snapshot percent complete: 0 Remove snapshot percent complete: 0 Remove
    snapshot percent complete: 0 Remove snapshot percent complete: 0 Remove snapshot percent complete: 0 Remove
    snapshot percent complete: 0 Remove snapshot percent complete: 0 Remove snapshot percent complete: 0 Remove
    snapshot percent complete: 0 Remove snapshot percent complete: 0 Remove snapshot percent complete: 0 Remove
    snapshot percent complete: 0 Remove snapshot percent complete: 0 Remove snapshot percent complete: 0 Remove
    snapshot percent complete: 0 Remove snapshot percent complete: 0 Remove snapshot percent complete: 0 Remove
    snapshot percent complete: 0 Remove snapshot percent complete: 0 Remove snapshot percent complete: 0 Remove
    snapshot percent complete: 0 Remove snapshot percent complete: 0 Remove snapshot percent complete: 0 Remove
    snapshot percent complete: 0 Remove snapshot percent complete: 0

Hi Racke,
Thanks for your suggestion
I have modified as per your instructions and used the callback plugins, It just formatted the lines to a compact form
but still somewhat not readable. Is there any way to present teh o/p in more refined way

Hello Rakesh,

how does it look like if you run the command outside of Ansible? I suppose it shows the progress and updates that
frequently, which could explain the jumbled output.

Regards
         Racke

Hi Racke,

Yes it gives me continuously this o/p on the powershell cli .
Remove snapshot

[ percent complete: 0

Hi Racke,
Yes it gives me continuously this o/p on the powershell cli .
Remove snapshot
[ percent complete: 0

Hello Rakesh,

so the solution for your problem would be to change the powershell script to suppress the progress meter
when called from Ansible.

Regards
         Racke

Hi Racke,

Thanks for the Suggestion , i have modified the pwsh script to run in “async” mode and it solved my issue and got some human readable format:
TASK [VMS-Mgmt : debug] ******************************************************************************************************************************************************************
ok: [BVXXXX] => (item={‘_ansible_parsed’: True, ‘stderr_lines’: , ‘_ansible_item_result’: True, u’end’: u’2019-11-26 01:17:55.494731’, ‘_ansible_no_log’: False, ‘_ansible_delegated_vars’: {‘ansible_delegated_host’: u’localhost’, ‘ansible_host’: u’localhost’}, u’cmd’: u’pwsh /home/raka/delete-snapshot.ps1’, u’rc’: 0, u’stdout’: u’\nName State % Complete Start Time Finish Time\n---- ----- ---------- ---------- -----------\nRemoveSnapshot_Task Running 0 01:17:55 AM ‘, ‘item’: u’BVXXXX’, u’delta’: u’0:00:06.928732’, ‘_ansible_item_label’: u’‘, u’stderr’: u’‘, u’changed’: False, u’invocation’: {u’module_args’: {u’warn’: True, u’executable’: None, u’_uses_shell’: True, u’_raw_params’: u’pwsh /home/raka/delete-snapshot.ps1’, u’removes’: None, u’argv’: None, u’creates’: None, u’chdir’: None, u’stdin’: None}}, ‘stdout_lines’: [u’‘, u’Name State % Complete Start Time Finish Time’, u’---- ----- ---------- ---------- -----------‘, u’RemoveSnapshot_Task Running 0 01:17:55 AM ‘], u’start’: u’2019-11-26 01:17:48.565999’, ‘_ansible_ignore_errors’: True, ‘failed’: False}) =>
msg:

  • ‘’
  • Name State % Complete Start Time Finish Time
  • ‘---- ----- ---------- ---------- -----------’
  • 'RemoveSnapshot_Task Running 0 01:17:55 AM ’