Repository: ansible/ansible

Issue:
constants.py should set to default port to None, not 22
I'm using the ssh config as a single location for holding all the confi
associated with connecting to a remote node, with the inventory
file just referencing the names of ssh host aliases, and use  ANSIBLE_TRANSPORT=ssh always.
It works great for most things (keys, IPs, jump hosts), but if a remote host
uses a non-standard port, ansible ignores the port specified in the ssh
config and tries to connect on port 22, which fails.



Discussion:
You should set ansible_ssh_port

another way to do this is, in inventory

hostname:1234

That means I have to put connection information in the inventory, duplicating the information in
the ssh config. It would be nicer not to have to.

```
[foo]
foo1
foo2


```

ssh config

```
Host foo1
 config_this
 config_that
 jump_3_hosts_here

Host foo2
 config_this
 config_that
 public_ip
```

That really seems like good practice to me.

Ok, looks to be a little off actually, constants.py should be setting the
SSH port to None, and it's setting the default to 22.

Thanks.

On Wed, Jun 26, 2013 at 5:49 PM, y-p notifications@github.com wrote:

> That means I have to put connection information in the inventory,
> duplicating the information in
> the ssh config. It would be nicer not to have to.
> 
> [foo]
> foo1
> foo2
> 
> [bar]
> bar1
> bar2
> 
> ssh config
> 
> Host foo1
>  config_this
>  config_that
>  jump_3_hosts_here
> 
> Host foo1
>   kerberos_twice_then_telnet
> 
> That really seems like good practice to me.
> 
> —
> Reply to this email directly or view it on GitHubhttps://github.com/ansible/ansible/issues/3352#issuecomment-20082761
> .


Resolving patch:
diff --git a/lib/ansible/constants.py b/lib/ansible/constants.py
--- a/lib/ansible/constants.py
+++ b/lib/ansible/constants.py
@@ -36,9 +36,9 @@ def get_config(p, section, key, env_var, default, boolean=False, integer=False,
     value = _get_config(p, section, key, env_var, default)
     if boolean:
         return mk_boolean(value)
-    if integer:
+    if value and integer:
         return int(value)
-    if floating:
+    if value and floating:
         return float(value)
     return value
 
@@ -114,7 +114,7 @@ def shell_expand_path(path):
 DEFAULT_PRIVATE_KEY_FILE  = shell_expand_path(get_config(p, DEFAULTS, 'private_key_file', 'ANSIBLE_PRIVATE_KEY_FILE', None))
 DEFAULT_SUDO_USER         = get_config(p, DEFAULTS, 'sudo_user',        'ANSIBLE_SUDO_USER',        'root')
 DEFAULT_ASK_SUDO_PASS     = get_config(p, DEFAULTS, 'ask_sudo_pass',    'ANSIBLE_ASK_SUDO_PASS',    False, boolean=True)
-DEFAULT_REMOTE_PORT       = get_config(p, DEFAULTS, 'remote_port',      'ANSIBLE_REMOTE_PORT',      22, integer=True)
+DEFAULT_REMOTE_PORT       = get_config(p, DEFAULTS, 'remote_port',      'ANSIBLE_REMOTE_PORT',      None, integer=True)
 DEFAULT_TRANSPORT         = get_config(p, DEFAULTS, 'transport',        'ANSIBLE_TRANSPORT',        'smart')
 DEFAULT_SCP_IF_SSH        = get_config(p, 'ssh_connection', 'scp_if_ssh',       'ANSIBLE_SCP_IF_SSH',       False, boolean=True)
 DEFAULT_MANAGED_STR       = get_config(p, DEFAULTS, 'ansible_managed',  None,           'Ansible managed: {file} modified on %Y-%m-%d %H:%M:%S by {uid} on {host}')


Test patch: