@@ -1219,6 +1219,12 @@ def __init__(self, *vargs, **kvargs):
12191219 *OPTIONAL* To disable public key authentication.
12201220 default is ``None``.
12211221
1222+ :param bool allow_agent:
1223+ *OPTIONAL* If ``True`` then the SSH config file is not parsed by PyEZ
1224+ and passed down to ncclient. If ``False`` then the SSH config file will
1225+ be parsed by PyEZ. If option is not provided will fallback to default
1226+ behavior. This option is passed down to the ncclient as is, if it is
1227+ present in the kwargs.
12221228 """
12231229
12241230 # ----------------------------------------
@@ -1237,6 +1243,7 @@ def __init__(self, *vargs, **kvargs):
12371243 self ._huge_tree = kvargs .get ("huge_tree" , False )
12381244 self ._conn_open_timeout = kvargs .get ("conn_open_timeout" , 30 )
12391245 self ._look_for_keys = kvargs .get ("look_for_keys" , None )
1246+ self ._allow_agent = kvargs .get ('allow_agent' , False )
12401247 if self ._fact_style != "new" :
12411248 warnings .warn (
12421249 "fact-style %s will be removed in a future "
@@ -1273,9 +1280,12 @@ def __init__(self, *vargs, **kvargs):
12731280 self ._auth_user = (
12741281 kvargs .get ("user" ) or self ._conf_auth_user or self ._auth_user
12751282 )
1276- self ._ssh_private_key_file = (
1277- kvargs .get ("ssh_private_key_file" ) or self ._conf_ssh_private_key_file
1278- )
1283+ if self ._allow_agent :
1284+ self ._ssh_private_key_file = kvargs .get ('ssh_private_key_file' )
1285+ else :
1286+ self ._ssh_private_key_file = (
1287+ kvargs .get ("ssh_private_key_file" ) or self ._conf_ssh_private_key_file
1288+ )
12791289 self ._auth_password = kvargs .get ("password" ) or kvargs .get ("passwd" )
12801290
12811291 # -----------------------------
@@ -1354,14 +1364,16 @@ def open(self, *vargs, **kvargs):
13541364 try :
13551365 ts_start = datetime .datetime .now ()
13561366
1357- # we want to enable the ssh-agent if-and-only- if we are
1367+ # enable the ssh-agent if asked, or if we are
13581368 # not given a password or an ssh key file.
13591369 # in this condition it means we want to query the agent
13601370 # for available ssh keys
1361-
1362- allow_agent = bool (
1363- (self ._auth_password is None ) and (self ._ssh_private_key_file is None )
1364- )
1371+ if self ._allow_agent is False :
1372+ allow_agent = bool (
1373+ (self ._auth_password is None ) and (self ._ssh_private_key_file is None )
1374+ )
1375+ else :
1376+ allow_agent = self ._allow_agent
13651377
13661378 # option to disable ncclient transport ssh authentication
13671379 # using public keys look_for_keys=False
0 commit comments