From 6aaa0c3252648faf33e247295b68e36713c83be8 Mon Sep 17 00:00:00 2001 From: Jacob McGill Date: Tue, 29 Aug 2017 13:28:58 -0400 Subject: [PATCH] Net Ping: Add new action plugin for *_ping network modules (#28558) --- .../modules/network/system/net_ping.py | 111 ++++++++++++++++++ lib/ansible/plugins/action/net_ping.py | 15 +++ 2 files changed, 126 insertions(+) create mode 100644 lib/ansible/modules/network/system/net_ping.py create mode 100644 lib/ansible/plugins/action/net_ping.py diff --git a/lib/ansible/modules/network/system/net_ping.py b/lib/ansible/modules/network/system/net_ping.py new file mode 100644 index 00000000000..ae1828e273e --- /dev/null +++ b/lib/ansible/modules/network/system/net_ping.py @@ -0,0 +1,111 @@ +#!/usr/bin/python +# -*- coding: utf-8 -*- + +# (c) 2017, Ansible by Red Hat, inc +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +from __future__ import absolute_import, division, print_function +__metaclass__ = type + + +ANSIBLE_METADATA = {'metadata_version': '1.1', + 'status': ['preview'], + 'supported_by': 'community'} + + +DOCUMENTATION = r''' +--- +module: net_ping +version_added: "2.4" +author: "Jacob McGill (@jmcgill298)" +short_description: Tests reachability using ping from a network device +description: + - Tests reachability using ping from network device to a remote destination. +options: + count: + description: + - Number of packets to send. + required: false + default: 5 + dest: + description: + - The IP Address or hostname (resolvable by switch) of the remote node. + required: true + source: + description: + - The source IP Address. + required: false + default: null + state: + description: + - Determines if the expected result is success or fail. + choices: [ absent, present ] + default: present + vrf: + description: + - The VRF to use for forwarding. + required: false + default: default +''' + + +EXAMPLES = r''' +- provider: + host: "{{ ansible_host }}" + username: "{{ username }}" + password: "{{ password }}" + network_os: "{{ network_os }}" + +- name: Test reachability to 10.10.10.10 using default vrf + net_ping: + provider: "{{ provider }}" + dest: 10.10.10.10 + +- name: Test reachability to 10.20.20.20 using prod vrf + net_ping: + provider: "{{ provider }}" + dest: 10.20.20.20 + vrf: prod + +- name: Test unreachability to 10.30.30.30 using default vrf + net_ping: + provider: "{{ provider }}" + dest: 10.30.30.30 + state: absent + +- name: Test reachability to 10.40.40.40 using prod vrf and setting count and source + net_ping: + provider: "{{ provider }}" + dest: 10.40.40.40 + source: loopback0 + vrf: prod + count: 20 +''' + +RETURN = r''' +commands: + description: Show the command sent. + returned: always + type: list + sample: ["ping vrf prod 10.40.40.40 count 20 source loopback0"] +packet_loss: + description: Percentage of packets lost. + returned: always + type: str + sample: "0%" +packets_rx: + description: Packets successfully received. + returned: always + type: int + sample: 20 +packets_tx: + description: Packets successfully transmitted. + returned: always + type: int + sample: 20 +rtt: + description: Show RTT stats. + returned: always + type: dict + sample: {"avg": 2, "max": 8, "min": 1} +''' diff --git a/lib/ansible/plugins/action/net_ping.py b/lib/ansible/plugins/action/net_ping.py new file mode 100644 index 00000000000..6cc78dd8825 --- /dev/null +++ b/lib/ansible/plugins/action/net_ping.py @@ -0,0 +1,15 @@ +# -*- coding: utf-8 -*- + +# (c) 2017, Ansible by Red Hat, inc +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +from __future__ import (absolute_import, division, print_function) +__metaclass__ = type + +from ansible.plugins.action.net_base import ActionModule as _ActionModule + + +class ActionModule(_ActionModule): + def run(self, tmp=None, task_vars=None): + result = super(ActionModule, self).run(tmp, task_vars) + return result