Need Debug Output

35 views
Skip to first unread message

Diptajeet Khan

unread,
Jan 24, 2019, 8:20:51 AM1/24/19
to Ansible Project
Hi,

Need help to fetch output from the below output message.

Bascially I need to extract "packet_loss", "packets_rx", "packets_tx", "rtt_avg", "rtt_max" & "rtt_min" for each "item".

Trying to use the code as

Code
=============:
- debug:
    var: "{{ item['packet_loss'] }}"
  with_items: "{{ output.results }}"
=============

Output:
=============
"results": [
{
"_ansible_ignore_errors": null,
"_ansible_item_label": {
"count": 5,
"dst": "192.168.1.3",
"packet_loss": null,
"packets_rx": null,
"packets_tx": null,
"rtt_avg": null,
"rtt_max": null,
"rtt_min": null,
"source": "192.168.1.1"
},
"_ansible_item_result": true,
"_ansible_no_log": false,
"_ansible_parsed": true,
"changed": false,
"commands": [
"ping 192.168.1.3 count 5 source 192.168.1.1"
],
"failed": false,
"invocation": {
"module_args": {
"auth_pass": null,
"authorize": null,
"count": "5",
"dest": "192.168.1.3",
"host": null,
"password": null,
"port": null,
"provider": null,
"source": "192.168.1.1",
"ssh_keyfile": null,
"state": "present",
"timeout": null,
"transport": null,
"use_ssl": null,
"username": null,
"validate_certs": null,
"vrf": null
}
},
"item": {
"count": 5,
"dst": "192.168.1.3",
"packet_loss": null,
"packets_rx": null,
"packets_tx": null,
"rtt_avg": null,
"rtt_max": null,
"rtt_min": null,
"source": "192.168.1.1"
},
"packet_loss": "0.00%",
"packets_rx": 5,
"packets_tx": 5,
"rtt": {
"avg": 0.67,
"max": 0.876,
"min": 0.585
}
},
{
"_ansible_ignore_errors": null,
"_ansible_item_label": {
"count": "N/A",
"dst": "N/A",
"packet_loss": null,
"packets_rx": null,
"packets_tx": null,
"rtt_avg": null,
"rtt_max": null,
"rtt_min": null,
"source": "N/A"
},
"_ansible_item_result": true,
"_ansible_no_log": false,
"changed": false,
"item": {
"count": "N/A",
"dst": "N/A",
"packet_loss": null,
"packets_rx": null,
"packets_tx": null,
"rtt_avg": null,
"rtt_max": null,
"rtt_min": null,
"source": "N/A"
},
"skip_reason": "Conditional result was False",
"skipped": true
},
{
"_ansible_ignore_errors": null,
"_ansible_item_label": {
"count": "N/A",
"dst": "N/A",
"packet_loss": null,
"packets_rx": null,
"packets_tx": null,
"rtt_avg": null,
"rtt_max": null,
"rtt_min": null,
"source": "N/A"
},
"_ansible_item_result": true,
"_ansible_no_log": false,
"changed": false,
"item": {
"count": "N/A",
"dst": "N/A",
"packet_loss": null,
"packets_rx": null,
"packets_tx": null,
"rtt_avg": null,
"rtt_max": null,
"rtt_min": null,
"source": "N/A"
},
"skip_reason": "Conditional result was False",
"skipped": true
},
{
"_ansible_ignore_errors": null,
"_ansible_item_label": {
"count": "N/A",
"dst": "N/A",
"packet_loss": null,
"packets_rx": null,
"packets_tx": null,
"rtt_avg": null,
"rtt_max": null,
"rtt_min": null,
"source": "N/A"
},
"_ansible_item_result": true,
"_ansible_no_log": false,
"changed": false,
"item": {
"count": "N/A",
"dst": "N/A",
"packet_loss": null,
"packets_rx": null,
"packets_tx": null,
"rtt_avg": null,
"rtt_max": null,
"rtt_min": null,
"source": "N/A"
},
"skip_reason": "Conditional result was False",
"skipped": true
==================

Karthik Chandrashekar

unread,
Jan 24, 2019, 8:31:04 AM1/24/19
to ansible...@googlegroups.com
May be you could try something like this. Register your output to some variable let's call it X. Then try to debug like below example.
Am exactly sure but, you can give a try.

 var="{X.results._ansible_item_label.{item}}"
with_item:
    - packet_lose
    - packet_rx

--
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 post to this group, send email to ansible...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/c6b832fd-47e8-4a10-87a4-1ef6aa868f02%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Diptajeet Khan

unread,
Jan 24, 2019, 8:43:01 AM1/24/19
to Ansible Project
Tried however doesnt work.

=> template error while templating string: expected name or number. String: {{{output.results._ansible_item_label.{item}}}}'

Diptajeet Khan

unread,
Jan 24, 2019, 6:36:34 PM1/24/19
to Ansible Project
Hi All,

Any hints to this?

Jonathan Lozada De La Matta

unread,
Jan 24, 2019, 6:57:06 PM1/24/19
to ansible...@googlegroups.com

On Thu, Jan 24, 2019 at 6:36 PM Diptajeet Khan <dipt...@gmail.com> wrote:
Hi All,

Any hints to this?

--
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 post to this group, send email to ansible...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.


--

Jonathan lozada de la matta

AUTOMATION PRACTICE



 

Diptajeet Khan

unread,
Jan 24, 2019, 9:07:27 PM1/24/19
to ansible...@googlegroups.com
Hi Jonathan,

Didn't get what is meant by following the link.

Best Regards
Diptajeet

Jonathan Lozada De La Matta

unread,
Jan 25, 2019, 7:53:56 AM1/25/19
to ansible...@googlegroups.com
You mentioned you needed debug output and I linked the docs that mentioned how to do it.


For more options, visit https://groups.google.com/d/optout.

Diptajeet Khan

unread,
Jan 25, 2019, 8:05:24 AM1/25/19
to ansible...@googlegroups.com
Ok but it was stuck mostly with parsing the debug output.

Best Regards
Diptajeet

Reply all
Reply to author
Forward
0 new messages