Repository: ansible/ansible

Issue:
eos_facts fails with error `"AF_UNIX path too long"` when debug log is enabled
<!---
Verify first that your issue/request is not already reported on GitHub.
Also test if the latest release, and master branch are affected too.
-->

##### ISSUE TYPE
<!--- Pick one below and delete the rest: -->
 - Bug Report

##### COMPONENT NAME
<!--- Name of the module/plugin/task/feature -->
bin/ansible-connection

##### ANSIBLE VERSION
<!--- Paste verbatim output from “ansible --version” between quotes below -->
```
2.4
```

##### CONFIGURATION
<!---
Mention any settings you have changed/added/removed in ansible.cfg
(or using the ANSIBLE_* environment variables).
-->

##### OS / ENVIRONMENT
<!---
Mention the OS you are running Ansible from, and the OS you are
managing, or say “N/A” for anything that is not platform-specific.
-->

##### SUMMARY
<!--- Explain the problem briefly -->

##### STEPS TO REPRODUCE
<!---
For bugs, show exactly how to reproduce the problem, using a minimal test-case.
For new features, show how the feature would be used.
-->
Enable debug logs and run below playbook
<!--- Paste example playbooks or commands between quotes below -->
```yaml
---
- name: Config using the core module
  hosts: veos02
  connection: local
  tasks:
    - name: Config Using Core Module
      eos_facts:
        authorize: yes
        provider:
          host: xxxx
          username: xxxx
          password: xxxx
          timeout: 30
        gather_subset: all
      register: response
```

<!--- You can also paste gist.github.com links for larger files -->

##### EXPECTED RESULTS
<!--- What did you expect to happen when running the steps above? -->
Should fetch facts from device

##### ACTUAL RESULTS
<!--- What actually happened? If possible run with extra verbosity (-vvvv) -->

<!--- Paste verbatim command output between quotes below -->
Error message:
```
fatal: [xxxx]: FAILED! => {
    "changed": false,
    "err": "AF_UNIX path too long",
    "failed": true,
    "invocation": {
        "module_args": {
            "auth_pass": null,
            "authorize": true,
            "gather_subset": [
                "all"
            ],
            "host": "veos02",
            "password": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER",
            "port": null,
            "provider": {
                "auth_pass": null,
                "authorize": true,
                "host": "xxxx",
                "password": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER",
                "port": null,
                "ssh_keyfile": null,
                "timeout": 30,
                "transport": null,
                "use_ssl": null,
                "username": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER",
                "validate_certs": null
            },
            "ssh_keyfile": null,
            "timeout": 30,
            "transport": "cli",
            "use_ssl": true,
            "username": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER",
            "validate_certs": true
        }
    },
    "msg": "unable to connect to socket"
}
```
Getting wrong socket-path from `ansible-connection`
```
<xxxx> socket_path:  47164 1497017236.67982: Loading Connection 'ssh' from /Users/xxxx/ansible/xxxx/platform_agnostic/ansible/lib/ansible/plugins/connection/ssh.py (found_in_cache=False, class_only=True)
/Users/xxxx/.ansible/pc/c215142d24
```

Expected path
```
<xxxx> socket_path: /Users/xxxx/.ansible/pc/c215142d24
```


Discussion:

Resolving patch:
diff --git a/lib/ansible/plugins/__init__.py b/lib/ansible/plugins/__init__.py
--- a/lib/ansible/plugins/__init__.py
+++ b/lib/ansible/plugins/__init__.py
@@ -343,6 +343,7 @@ def get(self, name, *args, **kwargs):
 
         found_in_cache = True
         class_only = kwargs.pop('class_only', False)
+        log_only = kwargs.pop('log_only', False)
         if name in self.aliases:
             name = self.aliases[name]
         path = self.find_plugin(name)
@@ -367,7 +368,7 @@ def get(self, name, *args, **kwargs):
                 return None
 
         self._display_plugin_load(self.class_name, name, self._searched_paths, path,
-                                  found_in_cache=found_in_cache, class_only=class_only)
+                                  found_in_cache=found_in_cache, class_only=class_only, log_only=log_only)
         if not class_only:
             try:
                 obj = obj(*args, **kwargs)
@@ -383,7 +384,7 @@ def get(self, name, *args, **kwargs):
         setattr(obj, '_load_name', name)
         return obj
 
-    def _display_plugin_load(self, class_name, name, searched_paths, path, found_in_cache=None, class_only=None):
+    def _display_plugin_load(self, class_name, name, searched_paths, path, found_in_cache=None, class_only=None, log_only=False):
         msg = 'Loading %s \'%s\' from %s' % (class_name, os.path.basename(name), path)
 
         if len(searched_paths) > 1:
@@ -392,7 +393,7 @@ def _display_plugin_load(self, class_name, name, searched_paths, path, found_in_
         if found_in_cache or class_only:
             msg = '%s (found_in_cache=%s, class_only=%s)' % (msg, found_in_cache, class_only)
 
-        display.debug(msg)
+        display.debug(msg, log_only)
 
     def all(self, *args, **kwargs):
         ''' instantiates all plugins with the same arguments '''
diff --git a/lib/ansible/utils/display.py b/lib/ansible/utils/display.py
--- a/lib/ansible/utils/display.py
+++ b/lib/ansible/utils/display.py
@@ -174,9 +174,9 @@ def vvvvv(self, msg, host=None):
     def vvvvvv(self, msg, host=None):
         return self.verbose(msg, host=host, caplevel=5)
 
-    def debug(self, msg):
+    def debug(self, msg, log_only=False):
         if C.DEFAULT_DEBUG:
-            self.display("%6d %0.5f: %s" % (os.getpid(), time.time(), msg), color=C.COLOR_DEBUG)
+            self.display("%6d %0.5f: %s" % (os.getpid(), time.time(), msg), color=C.COLOR_DEBUG, log_only=log_only)
 
     def verbose(self, msg, host=None, caplevel=2):
         if self.verbosity > caplevel:


Test patch: