cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
270
Views
1
Helpful
2
Replies

Ansible Netping

Netmart
Level 3
Level 3

Hello, 

I am trying to run a simple Ansible net_ping task, but for some reason it is not able to execute the command on switch:

It is probably something obvious I overlooked.

Though running the same command string in prompt mode directly on the switch, it is accepting it:

 

#ping ip 172.26.219.11 repeat 20 source 172.26.219.1
Type escape sequence to abort.
Sending 20, 100-byte ICMP Echos to 172.26.219.11, timeout is 2 seconds:
Packet sent with a source address of 172.26.219.1
!!!!!!!!!!!!!!!!!!!!

---

- name: Test network reachability

  hosts: iosxe  

  gather_facts: false

  tasks:

    - name: Ping the destination from the network device



      ansible.netcommon.net_ping:

       dest: 172.26.219.11

       source: 172.26.219.1

       count: 20

      register: ping_results


    - name: Display ping results

      debug:

        var: ping_results

 

debug:

run_commands

    return connection.run_commands(commands=commands, check_rc=check_rc)

  File "/usr/local/lib/python3.10/dist-packages/ansible/module_utils/connection.py", line 200, in __rpc__

    raise ConnectionError(to_text(msg, errors='surrogate_then_replace'), code=code)

fatal: [switch]: FAILED! => {

    "changed": false,

    "invocation": {

        "module_args": {

            "afi": "ip",

            "count": 20,

            "dest": "172.26.219.11",

            "df_bit": false,

            "egress": null,

            "ingress": null,

            "source": "172.26.219.1",

            "state": "present",

            "timeout": null,

            "vrf": null

        }

    },

    "msg": "ping ip 172.26.219.11 repeat 20 source 172.26.219.1\r\nTranslating \"ip\"...domain server (10.0.0.1)\r\n\r\nping ip 172.26.219.11 repeat 20 source 172.26.219.1\r\n                      ^\r\n% Invalid input detected at '^' marker.\r\n\r\nswitch>"

}

2 Replies 2

@Netmart hi, i am not sure why this getting ip domain lookup. you can try 'no ip domain-lookup' before run the script. in the same script check if any special characters included in command. you can copy paste exact command from the cli. those are few suggestions from my side to tshoot.

Please rate this and mark as solution/answer, if this resolved your issue
Good luck
KB

Couple of idea, use the https://docs.ansible.com/ansible/latest/collections/cisco/ios/ios_ping_module.html instead, from what i read, ansible.netcommon.net_ping is a generic module, and this why the syntax is broken (see your error marker). If you want to use this module, you would have to work around the that the module thinks 'ip' is a hostname, which is being added/inserted by net_ping module. Looking at the doc https://docs.ansible.com/ansible/2.9_ja/modules/net_ping_module.html - maybe? Not used Ansible in years.. so check this please!

 

- name: Test network reachability
  hosts: iosxe
  gather_facts: false
  tasks:
    - name: Ping the destination from the network device
      ansible.netcommon.net_ping:
        dest: 172.26.219.11
        source: loopback0  # or whatever interface has IP 172.26.219.1
        count: 20
      register: ping_results

    - name: Display ping results
      debug:
        var: ping_results

 

Please mark this as helpful or solution accepted to help others
Connect with me https://bigevilbeard.github.io