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 ansible_port=2222 ansible_user=dmitry

alias2 ansible_host=foo.example.com ansible_port=2233 ansible_user=dmitry


понедельник, 13 марта 2017 г., 16:38:34 UTC+3 пользователь Dmitriy 
Lomanchuk написал:
>
> 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
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/90655346-d818-489f-af9c-df2c74f26195%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to