Repository: ansible/ansible

Issue:
EOS cli transport ignores port
<!---
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
 - Bug Report

##### COMPONENT NAME
<!--- Name of the module/plugin/task/feature -->
eos

##### ANSIBLE VERSION
<!--- Paste verbatim output from “ansible --version” between quotes below -->
```
ansible 2.4.0 (devel 3965689328) last updated 2017/04/20 11:27:40 (GMT -400)
```

##### 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.
-->
N/A

##### SUMMARY
<!--- Explain the problem briefly -->
At some point (3537b247429a94c838eefc2f5cc3ba3448d61913?) during the persistent connection rewrite, EOS lost the ability to have port specified from the playbook. While it is still possible to control this from the command line and the default value of 22 works in many instances, this is still a regression from 2.2


Discussion:

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
@@ -60,7 +60,6 @@
 # Add argument's default value here
 ARGS_DEFAULT_VALUE = {
     'transport': 'cli',
-    'port': 443,
     'use_ssl': True,
     'validate_certs': True
 }
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
@@ -24,9 +24,8 @@
 import copy
 
 from ansible.module_utils.basic import AnsibleFallbackNotFound
-from ansible.module_utils.eos import eos_argument_spec
+from ansible.module_utils.eos import ARGS_DEFAULT_VALUE, eos_argument_spec
 from ansible.module_utils.six import iteritems
-from ansible.module_utils._text import to_bytes
 from ansible.plugins import connection_loader
 from ansible.plugins.action.normal import ActionModule as _ActionModule
 from ansible.utils.path import unfrackpath
@@ -58,6 +57,7 @@ def run(self, tmp=None, task_vars=None):
             pc.connection = 'network_cli'
             pc.network_os = 'eos'
             pc.remote_addr = provider['host'] or self._play_context.remote_addr
+            pc.port = provider['port'] or self._play_context.port or 22
             pc.remote_user = provider['username'] or self._play_context.connection_user
             pc.password = provider['password'] or self._play_context.password
             pc.private_key_file = provider['ssh_keyfile'] or self._play_context.private_key_file
@@ -96,8 +96,12 @@ def run(self, tmp=None, task_vars=None):
             if provider.get('host') is None:
                 provider['host'] = self._play_context.remote_addr
 
+            if provider.get('use_ssl') is None:
+                provider['use_ssl'] = ARGS_DEFAULT_VALUE['use_ssl']
+
             if provider.get('port') is None:
-                provider['port'] = eos_argument_spec['port']['default']
+                default_port = 443 if provider['use_ssl'] else 80
+                provider['port'] = self._play_context.port or default_port
 
             if provider.get('timeout') is None:
                 provider['timeout'] = self._play_context.timeout
@@ -111,11 +115,8 @@ def run(self, tmp=None, task_vars=None):
             if provider.get('authorize') is None:
                 provider['authorize'] = False
 
-            if provider.get('use_ssl') is None:
-                provider['use_ssl'] = eos_argument_spec['use_ssl']['default']
-
             if provider.get('validate_certs') is None:
-                provider['validate_certs'] = eos_argument_spec['validate_certs']['default']
+                provider['validate_certs'] = ARGS_DEFAULT_VALUE['validate_certs']
 
             self._task.args['provider'] = provider
 


Test patch: