From 1699a39ad0f2948b45944929755ecb6bb0b65f60 Mon Sep 17 00:00:00 2001 From: Peter Sprygada Date: Thu, 7 Dec 2017 09:47:41 -0500 Subject: [PATCH] fixes guess_os for netconf connections (#33671) * fixes guess_os for netconf connections This change fixes invalid calls to play_context when the network_os is not set and the connection attempts to guess the network_os. The method will now check the correct values for ssh key file and allow agent instead of returning errors. * fix up pep8 issues --- lib/ansible/plugins/connection/netconf.py | 3 ++- lib/ansible/plugins/netconf/iosxr.py | 4 ++-- lib/ansible/plugins/netconf/junos.py | 4 ++-- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/lib/ansible/plugins/connection/netconf.py b/lib/ansible/plugins/connection/netconf.py index 5cf4a442a7d..56fad9c53bc 100644 --- a/lib/ansible/plugins/connection/netconf.py +++ b/lib/ansible/plugins/connection/netconf.py @@ -164,6 +164,7 @@ class Connection(ConnectionBase): allow_agent = True if self._play_context.password is not None: allow_agent = False + setattr(self._play_context, 'allow_agent', allow_agent) key_filename = None if self._play_context.private_key_file: @@ -195,7 +196,7 @@ class Connection(ConnectionBase): key_filename=str(key_filename), hostkey_verify=C.HOST_KEY_CHECKING, look_for_keys=C.PARAMIKO_LOOK_FOR_KEYS, - allow_agent=allow_agent, + allow_agent=self._play_context.allow_agent, timeout=self._play_context.timeout, device_params={'name': network_os}, ssh_config=ssh_config diff --git a/lib/ansible/plugins/netconf/iosxr.py b/lib/ansible/plugins/netconf/iosxr.py index e97a7dc3bc2..eee3eade142 100644 --- a/lib/ansible/plugins/netconf/iosxr.py +++ b/lib/ansible/plugins/netconf/iosxr.py @@ -141,10 +141,10 @@ class Netconf(NetconfBase): port=obj._play_context.port or 830, username=obj._play_context.remote_user, password=obj._play_context.password, - key_filename=str(obj.key_filename), + key_filename=obj._play_context.private_key_file, hostkey_verify=C.HOST_KEY_CHECKING, look_for_keys=C.PARAMIKO_LOOK_FOR_KEYS, - allow_agent=obj.allow_agent, + allow_agent=obj._play_context.allow_agent, timeout=obj._play_context.timeout ) except SSHUnknownHostError as exc: diff --git a/lib/ansible/plugins/netconf/junos.py b/lib/ansible/plugins/netconf/junos.py index cb61e62869e..1c29f852537 100644 --- a/lib/ansible/plugins/netconf/junos.py +++ b/lib/ansible/plugins/netconf/junos.py @@ -107,10 +107,10 @@ class Netconf(NetconfBase): port=obj._play_context.port or 830, username=obj._play_context.remote_user, password=obj._play_context.password, - key_filename=str(obj.key_filename), + key_filename=obj._play_context.private_key_file, hostkey_verify=C.HOST_KEY_CHECKING, look_for_keys=C.PARAMIKO_LOOK_FOR_KEYS, - allow_agent=obj.allow_agent, + allow_agent=obj._play_context.allow_agent, timeout=obj._play_context.timeout ) except SSHUnknownHostError as exc: