From d1ff8e2dca1883963dfb33daaaf2001d018d6ce4 Mon Sep 17 00:00:00 2001 From: "Ganesh B. Nalawade" Date: Wed, 4 Jul 2018 11:37:35 +0530 Subject: [PATCH] Update ssh_config to accept file path --- .../user_guide/network_debug_troubleshooting.rst | 11 +++++++---- lib/ansible/config/base.yml | 7 ++++--- lib/ansible/plugins/connection/netconf.py | 15 ++++++++------- 3 files changed, 19 insertions(+), 14 deletions(-) diff --git a/docs/docsite/rst/network/user_guide/network_debug_troubleshooting.rst b/docs/docsite/rst/network/user_guide/network_debug_troubleshooting.rst index af4e0f1f21d..8bd1d21dd42 100644 --- a/docs/docsite/rst/network/user_guide/network_debug_troubleshooting.rst +++ b/docs/docsite/rst/network/user_guide/network_debug_troubleshooting.rst @@ -604,11 +604,14 @@ Enabling jump host setting -------------------------- Bastion/jump host with netconf connection can be enable using -- Setting Ansible variable``ansible_netconf_ssh_config`` or -- Setting environment variable ``ANSIBLE_NETCONF_SSH_CONFIG`` or -- Setting ``ssh_config=Ture`` under ``netconf_connection`` section in ansible configuration file +- Setting Ansible variable``ansible_netconf_ssh_config`` either to ``True`` or custom ssh config file path +- Setting environment variable ``ANSIBLE_NETCONF_SSH_CONFIG`` to ``True`` or custom ssh config file path +- Setting ``ssh_config = 1`` or ``ssh_config = ``under ``netconf_connection`` section -The ssh config file (~/.ssh/config) should have the correct proxycommand and required ssh configuration variables +If the configuration variable is set to 1 the proxycommand and other ssh variables are read from +default ssh config file (~/.ssh/config). +If the configuration variable is set to file path the proxycommand and other ssh variables are read +from the given custom ssh file path Example ssh config file (~/.ssh/config) --------------------------------------- diff --git a/lib/ansible/config/base.yml b/lib/ansible/config/base.yml index 3a413a8ae5b..d7b64e14e34 100644 --- a/lib/ansible/config/base.yml +++ b/lib/ansible/config/base.yml @@ -1633,11 +1633,12 @@ YAML_FILENAME_EXTENSIONS: key: yaml_valid_extensions type: list NETCONF_SSH_CONFIG: - description: This variable is used to enable bastion/jump host with netconf connection. The bastion/jump - host ssh settings should be present in ssh configuration file (~/.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. env: [{name: ANSIBLE_NETCONF_SSH_CONFIG}] ini: - {key: ssh_config, section: netconf_connection} yaml: {key: netconf_connection.ssh_config} - type: boolean + default: None ... diff --git a/lib/ansible/plugins/connection/netconf.py b/lib/ansible/plugins/connection/netconf.py index 0db23ff0e7d..d886085c491 100644 --- a/lib/ansible/plugins/connection/netconf.py +++ b/lib/ansible/plugins/connection/netconf.py @@ -153,11 +153,12 @@ options: env: - name: ANSIBLE_PERSISTENT_COMMAND_TIMEOUT netconf_ssh_config: - type: boolean - default: False + default: None description: - - This variable is used to enable bastion/jump host with netconf connection. The bastion/jump - host ssh settings should be present in ssh configuration file (~/.ssh/config). + - 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 @@ -175,7 +176,7 @@ import json 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 @@ -202,7 +203,7 @@ NETWORK_OS_DEVICE_PARAM_MAP = { "ce": "huawei" } - +import q class Connection(NetworkConnectionBase): """NetConf connections""" @@ -266,7 +267,7 @@ class Connection(NetworkConnectionBase): 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: