From 4937dd67e448d5fc0b1ebf86b99f8b49ced0dc8d Mon Sep 17 00:00:00 2001 From: Peter Sprygada Date: Tue, 3 Jan 2017 22:33:02 -0500 Subject: [PATCH] adds new feature to network_cli (#19848) In some cases it is desirable to have a send only function that doesn't wait for the response from the CLI (such as reloading a device). This adds a new key to the command json string sendonly that will achieve this behavior. --- lib/ansible/plugins/connection/network_cli.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/ansible/plugins/connection/network_cli.py b/lib/ansible/plugins/connection/network_cli.py index 6cec05a510..db01ec8ba0 100644 --- a/lib/ansible/plugins/connection/network_cli.py +++ b/lib/ansible/plugins/connection/network_cli.py @@ -149,6 +149,8 @@ class Connection(_Connection): command = obj['command'] self._history.append(command) self._shell.sendall('%s\r' % command) + if obj.get('sendonly'): + return return self.receive(obj) except (socket.timeout, AttributeError): raise AnsibleConnectionFailure("timeout trying to send command: %s" % command.strip()) @@ -206,15 +208,13 @@ class Connection(_Connection): * command - the command string to execute * prompt - the expected prompt generated by executing command * response - the string to respond to the prompt with + * sendonly - bool to disable waiting for response :arg cmd: the string that represents the command to be executed which can be a single command or a json encoded string :returns: a tuple of (return code, stdout, stderr). The return code is an integer and stdout and stderr are strings """ - # TODO: add support for timeout to the cmd to handle non return - # commands such as a system restart - try: obj = json.loads(cmd) except ValueError: