TTP parsing doesn't work in ansible, need assistance

I wrote below script to parse output of ‘sh flash:’ however iam getting blank output.

I checked several examples and i seem to be following the format properly yet doesn’t work. What am i doing wrong?

SCRIPT:

ios_command:
commands: “show flash:”

register: show_space

name: Pass text and template_path
ansible.utils.cli_parse:
text: “{{ show_space[‘stdout’] }}”
parser:
name: ansible.utils.ttp
template_path: “templates/sample.ttp”

register: parser_output

name: Display facts
debug:
msg: “{{ parser_output.parsed }}”

TTP TEMPLATE:
cat nano templates/sample.ttp
Directory of {{ path }}
{{ bytes_total }} bytes total ({{ bytes_free }} bytes free)

try removing quotes in stdout

“{{ show_space.stdout }}” try in this way

Hi Pushparaj,

TRhanks for your suggestion, modifying syntax helped!!
But it’s ironical that ansible’s own documentation would give wrong syntax as earlier syntax was taken from sample example given in ansible site.

Below is the output i get, how do i compare value of ‘bytes_free’ to a number? i wrote the below syntax but didn’t work.

  • assert:
    that:
  • parser_output[‘flash:’][‘bytes_free’] > 440320
    fail_msg: “DEVICE MODEL IS NOT 2960x. SO PLAYBOOK IS ENDING.”

WORKING SCRIPT:

TASK [Display facts] **********************************************************************************************************************************************************************************************
ok: [SW6] => {
“msg”: [
[
{
“flash:/”: {
“bytes_free”: 22840320,
“bytes_total”: 122185728

  • name: Pass text and template_path
    ansible.utils.cli_parse:
    text: “{{ show_space.stdout[0] }}”
    parser:
    name: ansible.utils.ttp
    template_path: “templates/sample2.ttp”

register: parser_output

Thanks,
Vikram