# Ansible 2.2.1.0 aliases does not work as expected

**URL:** <https://forum.ansible.com/t/ansible-2-2-1-0-aliases-does-not-work-as-expected/23949>\
**Category:** Ansible Project\
**Created:** [March 13, 2017, 11:28am UTC](https://forum.ansible.com/t/ansible-2-2-1-0-aliases-does-not-work-as-expected/23949 "2017-03-13T11:28:24Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dmitriy\_Lomanchuk](https://avatars.discourse-cdn.com/v4/letter/d/e99b99/32.png) [@Dmitriy\_Lomanchuk](https://forum.ansible.com/u/Dmitriy_Lomanchuk)\
**Post date:** [March 13, 2017, 11:28am UTC](https://forum.ansible.com/t/ansible-2-2-1-0-aliases-does-not-work-as-expected/23949/1 "2017-03-13T11:28:24Z")

</div>

Hi everybody!

It seems, inventory aliases does not work if trying to connect to hosts behind NAT with same address and different ssh\_port.

I,m wondering, if I have made some mistake in configuration, or it is a bug or known feature?

**Ansible version:**

`d.lomanchuk@LenovoX220i:~/.ansible$ ansible --version ansible 2.2.1.0 config file = /etc/ansible/ansible.cfg configured module search path = Default w/o overrides`

**My inventory:**

` d.lomanchuk@LenovoX220i:~/.ansible$ cat test_inventory [denet] mycoolbox ansible_host=192.168.1.202 ansible_port=2210 ansible_user=dmitry ansible_password= ******* le_lxc ansible_host=192.168.1.202 ansible_port=2323 ansible_user=dmitry ansible_password=`\*\*\*\*\*\*\*`

`

Trying to ping hosts i see failures sometimes:

`  
d.lomanchuk@LenovoX220i:~/.ansible$ ansible -i test\_inventory -m ping all  
le\_lxc | FAILED! =\> {  
“failed”: true,  
“msg”: “failed to transfer file to /home/dmitry/.ansible/tmp/ansible-tmp-1489399666.62-12650861868843/ping.py:\n\nscp: /home/dmitry/.ansible/tmp/ansible-tmp-1489399666.62-12650861868843/ping.py: No such file or directory\n”  
}  
mycoolbox | SUCCESS =\> {  
“changed”: false,  
“ping”: “pong”  
}

`

But, if I try to ping them again immediately after such failure, everything looks good:

`d.lomanchuk@LenovoX220i:~/.ansible$ ansible -i test_inventory -m ping all`  
`mycoolbox | SUCCESS => {`  
`"changed": false,`  
`"ping": "pong"`  
`}`  
`le_lxc | SUCCESS => {`  
`"changed": false,`  
`"ping": "pong"`  
`}`

However, if I try to run _hostname_ command via “shell” module immediately after that, I see that ansible connects to the same host (one of all):

`  
d.lomanchuk@LenovoX220i:~/.ansible$ ansible -i test\_inventory -m shell -a “hostname” all  
le\_lxc | SUCCESS | rc=0 \>\>  
denetpbx

mycoolbox | SUCCESS | rc=0 \>\>  
denetpbx

`

Aliases works as expected, only if I type them in /etc/hosts on my machine.

`

d.lomanchuk@LenovoX220i:~/.ansible$ tail -n 2 /etc/hosts  
192.168.1.202 mycoolbox  
192.168.1.202 le\_lxc  
`

Then, everything works as expected.

`  
d.lomanchuk@LenovoX220i:~/.ansible$ ansible -i test\_inventory -m shell -a “hostname” all  
le\_lxc | SUCCESS | rc=0 \>\>  
letsencrypt

mycoolbox | SUCCESS | rc=0 \>\>  
denetpbx

`

---

<div class="post-metadata">

**Author:** ![Dmitriy\_Lomanchuk](https://avatars.discourse-cdn.com/v4/letter/d/e99b99/32.png) [@Dmitriy\_Lomanchuk](https://forum.ansible.com/u/Dmitriy_Lomanchuk)\
**Post date:** [March 27, 2017, 4:39pm UTC](https://forum.ansible.com/t/ansible-2-2-1-0-aliases-does-not-work-as-expected/23949/2 "2017-03-27T16:39:53Z")

</div>

It was my silly configuration mistake.

There are a lot of servers with very long hostnames in my network.  
That is why I changed ansible.cfg control\_path parameter to:  
So, if ansible\_host and ansible\_user are the same for multiple hosts - the problem occures.

` `control\_path = %(directory)s/%%h-%%r` `

For example:

`  
[test-servers]

alias1 ansible\_host=[foo.example.com](http://foo.example.com) ansible\_port=2222 ansible\_user=dmitry

alias2 ansible\_host=[foo.example.com](http://foo.example.com) ansible\_port=2233 ansible\_user=dmitry  
`
