TTP parsing doesn't work in ansible, need assistance

16 views
Skip to first unread message

Vikram S

unread,
Apr 21, 2021, 6:04:13 AM4/21/21
to Ansible Project

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)
----------------------------------------------------------------------
OUTPUT:
TASK [Display facts] *****************************************************
ok: [TEST2960] => {
"msg": [
[
     {}
   ]
 ]
}

Thanks,
Vikram

Rajthecomputerguy

unread,
Apr 21, 2021, 7:30:00 AM4/21/21
to ansible...@googlegroups.com
try removing quotes in stdout



--
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/14299988-a84c-468f-ac83-b89bf461f7ccn%40googlegroups.com.


--

Thanks,

Pushparaj G


Komal Suthar

unread,
Apr 21, 2021, 10:03:55 AM4/21/21
to ansible...@googlegroups.com
"{{ show_space.stdout }}" try in this way

Vikram S

unread,
Apr 21, 2021, 10:17:44 AM4/21/21
to Ansible Project
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

Reply all
Reply to author
Forward
0 new messages