Repository: ansible/ansible

Issue:
eos: connection: TypeError: argument must be string or read-only character buffer, not None
##### ISSUE TYPE
 - Bug Report

##### COMPONENT NAME
eos_command

##### ANSIBLE VERSION
```
ansible 2.3.0 (test_ios_again 1dde9971ae) last updated 2017/02/23 09:43:19 (GMT +100)

```

##### SUMMARY

##### STEPS TO REPRODUCE
```yaml
- name: test gt operator
  eos_command:
    commands:
      - show version
      - show interfaces Management1
    wait_for:
      - "result[1].interfaces.Management1.mtu gt 0"
    provider: "{{ eapi }}"
  register: result

```


##### EXPECTED RESULTS

##### ACTUAL RESULTS
```
 [WARNING]: Removed unexpected internal key in module return: _ansible_parsed = False

An exception occurred during task execution. The full traceback is:
Traceback (most recent call last):
  File "/tmp/ansible_dG8x1A/ansible_module_eos_command.py", line 240, in <module>
    main()
  File "/tmp/ansible_dG8x1A/ansible_module_eos_command.py", line 210, in main
    responses = run_commands(module, commands)
  File "/tmp/ansible_dG8x1A/ansible_modlib.zip/ansible/module_utils/eos.py", line 426, in run_commands
  File "/tmp/ansible_dG8x1A/ansible_modlib.zip/ansible/module_utils/eos.py", line 145, in run_commands
  File "/tmp/ansible_dG8x1A/ansible_modlib.zip/ansible/module_utils/eos.py", line 110, in exec_command
  File "/tmp/ansible_dG8x1A/ansible_modlib.zip/ansible/module_utils/connection.py", line 60, in exec_command
  File "/usr/lib/python2.7/socket.py", line 228, in meth
    return getattr(self._sock,name)(*args)
TypeError: argument must be string or read-only character buffer, not None

fatal: [veos01]: FAILED! => {
    "changed": false, 
    "failed": true, 
    "module_stderr": "Traceback (most recent call last):\n  File \"/tmp/ansible_dG8x1A/ansible_module_eos_command.py\", line 240, in <module>\n    main()\n  File \"/tmp/ansible_dG8x1A/ansible_module_eos_command.py\", line 210, in main\n    responses = run_commands(module, commands)\n  File \"/tmp/ansible_dG8x1A/ansible_modlib.zip/ansible/module_utils/eos.py\", line 426, in run_commands\n  File \"/tmp/ansible_dG8x1A/ansible_modlib.zip/ansible/module_utils/eos.py\", line 145, in run_commands\n  File \"/tmp/ansible_dG8x1A/ansible_modlib.zip/ansible/module_utils/eos.py\", line 110, in exec_command\n  File \"/tmp/ansible_dG8x1A/ansible_modlib.zip/ansible/module_utils/connection.py\", line 60, in exec_command\n  File \"/usr/lib/python2.7/socket.py\", line 228, in meth\n    return getattr(self._sock,name)(*args)\nTypeError: argument must be string or read-only character buffer, not None\n", 
    "module_stdout": "", 
    "msg": "MODULE FAILURE", 
    "rc": 0
}

```



Discussion:
cc @privateip @Qalthos
[click here for bot help](https://github.com/ansible/ansibullbot/blob/master/ISSUE_HELP.md)
<!--- boilerplate: notify --->

Resolving patch:
diff --git a/lib/ansible/module_utils/eos.py b/lib/ansible/module_utils/eos.py
--- a/lib/ansible/module_utils/eos.py
+++ b/lib/ansible/module_utils/eos.py
@@ -79,9 +79,9 @@ def get_connection(module):
     global _DEVICE_CONNECTION
     if not _DEVICE_CONNECTION:
         load_params(module)
-        if 'transport' not in module.params:
-            conn = Cli(module)
-        elif module.params['transport'] == 'eapi':
+        transport = module.params['transport']
+        provider_transport = (module.params['provider'] or {}).get('transport')
+        if 'eapi' in (transport, provider_transport):
             conn = Eapi(module)
         else:
             conn = Cli(module)
diff --git a/lib/ansible/plugins/action/eos.py b/lib/ansible/plugins/action/eos.py
--- a/lib/ansible/plugins/action/eos.py
+++ b/lib/ansible/plugins/action/eos.py
@@ -87,6 +87,7 @@ def run(self, tmp=None, task_vars=None):
 
         else:
             provider_arg = {
+                'transport': 'eapi',
                 'host': provider.get('host') or self._play_context.remote_addr,
                 'port': provider.get('port'),
                 'username': provider.get('username') or self._play_context.connection_user,


Test patch: