Fix network_cli exec_command connection init (#62344)

* Fix network_cli exec_command connection init

Fixes https://github.com/ansible/ansible/issues/61596

*  If `exec_command` method is invoked from module side
   on connection object to execute the command on target
   host check if connection is created if not create the
   connection.

* Fix review comment
This commit is contained in:
Ganesh Nalawade 2019-09-17 18:30:54 +05:30 committed by Nathaniel Case
parent 7a5a5e7c87
commit 74e4993628

View file

@ -138,6 +138,10 @@ class ConnectionProcess(object):
if log_messages: if log_messages:
display.display("jsonrpc request: %s" % data, log_only=True) display.display("jsonrpc request: %s" % data, log_only=True)
request = json.loads(to_text(data, errors='surrogate_or_strict'))
if request.get('method') == "exec_command" and not self.connection.connected:
self.connection._connect()
signal.alarm(self.connection.get_option('persistent_command_timeout')) signal.alarm(self.connection.get_option('persistent_command_timeout'))
resp = self.srv.handle_request(data) resp = self.srv.handle_request(data)