Repository: ansible/ansible

Issue:
netconf module does not respect ansible_ssh_common_args
<!---
Verify first that your issue/request is not already reported on GitHub.
Also test if the latest release, and devel branch are affected too.
-->

##### ISSUE TYPE
 - Bug Report
 - Documentation Report

##### COMPONENT NAME
netconf
junos_config

##### ANSIBLE VERSION
```
ansible 2.4.2.0
```

##### CONFIGURATION
<!---
If using Ansible 2.4 or above, paste the results of "ansible-config dump --only-changed"
Otherwise, mention any settings you have changed/added/removed in ansible.cfg
(or using the ANSIBLE_* environment variables).
-->

##### OS / ENVIRONMENT
N/A

##### SUMMARY
When attempting to use jump hosts with a netconf host (i've only tested with JunOS, but im assuming all modules that rely on the netconf module), the netconf module does not examine ansible_ssh_common_args, and so will fail to connect to the remote host.

This is likely due to the dependency of ncclient, and that ncclient does not allow paramiko options to be passed through. The only option available is whether or not to parse an ssh config file (e.g ~/.ssh/config).

The netconf module supports this via setting ANSIBLE_NETCONF_SSH_CONFIG in an environment variable, but it seems non-standard and undocumented.

The ANSIBLE_NETCONF_SSH_CONFIG environment variable documentation has been removed in a previous commit(https://github.com/ansible/ansible/pull/33396/files#diff-e8614475b293e6b754610340212f8d3aL34) . It would be nice to be able to be set via a variable on playbook runs so that SSH config can be parsed for things like ProxyCommand. The old documentation suggests this was intended, but I don't believe the code was ever written to do so (https://github.com/ansible/ansible/blob/75a34f666826be988b25df41cb72bcd5d1428736/lib/ansible/plugins/connection/netconf.py#L243)

At the moment I believe this is the only way to make the netconf module use a jump host, so for environments such as AWX where you can't set environment variables (at least ANSIBLE_* ones) for playbook runs, this would be required. The documentation regarding jump hosts will probably need to be updated to reflect that netconf does not respect ansible_ssh_common_args as well.




Discussion:
Files identified in the description:
* [lib/ansible/modules/network/junos/junos_config.py](https://github.com/ansible/ansible/blob/devel/lib/ansible/modules/network/junos/junos_config.py)
* [lib/ansible/modules/network/netconf/netconf_config.py](https://github.com/ansible/ansible/blob/devel/lib/ansible/modules/network/netconf/netconf_config.py)

If these files are inaccurate, please update the `component name` section of the description or use the `!component` bot command.

[click here for bot help](https://github.com/ansible/ansibullbot/blob/master/ISSUE_HELP.md)
<!--- boilerplate: components_banner --->
cc @Qalthos @ganeshrn @lpenz @privateip @userlerueda
[click here for bot help](https://github.com/ansible/ansibullbot/blob/master/ISSUE_HELP.md)
<!--- boilerplate: notify --->
Is this at all similar to what I was running into regarding my post?:  
Ansible 2.5 ssh-common-args ignored. (#36335)
Files identified in the description:
* [lib/ansible/module_utils/network/common/netconf.py](https://github.com/ansible/ansible/blob/devel/lib/ansible/module_utils/network/common/netconf.py)
* [lib/ansible/modules/network/junos/junos_config.py](https://github.com/ansible/ansible/blob/devel/lib/ansible/modules/network/junos/junos_config.py)

If these files are inaccurate, please update the `component name` section of the description or use the `!component` bot command.

[click here for bot help](https://github.com/ansible/ansibullbot/blob/master/ISSUE_HELP.md)
<!--- boilerplate: components_banner --->
cc @gdpak @gundalow @rcarrillocruz @trishnaguha
[click here for bot help](https://github.com/ansible/ansibullbot/blob/master/ISSUE_HELP.md)
<!--- boilerplate: notify --->
Anything new on this?

Still having this issue on Ansible 2.5.5

Resolving patch:
diff --git a/lib/ansible/plugins/connection/netconf.py b/lib/ansible/plugins/connection/netconf.py
--- a/lib/ansible/plugins/connection/netconf.py
+++ b/lib/ansible/plugins/connection/netconf.py
@@ -152,6 +152,21 @@
         key: command_timeout
     env:
       - name: ANSIBLE_PERSISTENT_COMMAND_TIMEOUT
+  netconf_ssh_config:
+    description:
+      - This variable is used to enable bastion/jump host with netconf connection. If set to
+        True the bastion/jump host ssh settings should be present in ~/.ssh/config file,
+        alternatively it can be set to custom ssh configuration file path to read the
+        bastion/jump host settings.
+    ini:
+      - section: netconf_connection
+        key: ssh_config
+        version_added: '2.7'
+    env:
+      - name: ANSIBLE_NETCONF_SSH_CONFIG
+    vars:
+      - name: ansible_netconf_ssh_config
+        version_added: '2.7'
 """
 
 import os
@@ -160,7 +175,7 @@
 
 from ansible.errors import AnsibleConnectionFailure, AnsibleError
 from ansible.module_utils._text import to_bytes, to_native, to_text
-from ansible.module_utils.parsing.convert_bool import BOOLEANS_TRUE
+from ansible.module_utils.parsing.convert_bool import BOOLEANS_TRUE, BOOLEANS_FALSE
 from ansible.plugins.loader import netconf_loader
 from ansible.plugins.connection import NetworkConnectionBase
 
@@ -248,10 +263,10 @@ def _connect(self):
 
         device_params = {'name': NETWORK_OS_DEVICE_PARAM_MAP.get(self._network_os) or self._network_os}
 
-        ssh_config = os.getenv('ANSIBLE_NETCONF_SSH_CONFIG', False)
+        ssh_config = self.get_option('netconf_ssh_config')
         if ssh_config in BOOLEANS_TRUE:
             ssh_config = True
-        else:
+        elif ssh_config in BOOLEANS_FALSE:
             ssh_config = None
 
         try:


Test patch: