Same host in inventory twice with two different ports, not working

578 views
Skip to first unread message

John Gateley

unread,
Apr 28, 2016, 7:11:48 PM4/28/16
to Ansible Project
Hello,

I have an inventory file with the same host twice, once using ssh on port 22, once using ssh on port 12345. This is inventory file bad.hosts2:

[host1]

foo.example.com:22  ansible_connection=ssh ansible_ssh_user=root


[host2]

foo.example.com:12345       ansible_connection=ssh ansible_ssh_user=root


The intent is to use one host (host1) to copy a new sshd config file and to setup sshd to run on a different port. From then on, the second host (host2) would be used.

However, the behavior is strange: no matter what I do, port 22 is used.


Johns-MacBook-Air:ansible.bug j$ ansible -i bad.hosts2 -m ping host1

foo.example.com| success >> {

    "changed": false, 

    "ping": "pong"

}


Johns-MacBook-Air:ansible.bug j$ ansible -i bad.hosts2 -m ping host2

foo.example.com | success >> {

    "changed": false, 

    "ping": "pong"

}


Note sshd is only running on port 22, and if I switch the order of the two hosts in the inventory file, both host1 and host2 will fail the ping.


What is happening here?


Thanks


John




Matt Martz

unread,
Apr 28, 2016, 7:28:48 PM4/28/16
to ansible...@googlegroups.com
Instead of using groups, you should likely use aliases such as:

host1 ansible_host=foo.example.com ansible_port=22
host2 ansible_host=foo.example.com ansible_port=12345

Inventory names in Ansible are unique, so aliasing like that allows you to duplicate a host, while keep configurations for each different.
--
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 ansible-proje...@googlegroups.com.
To post to this group, send email to ansible...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/1b48f84a-aa8f-4e38-be09-b3908019b25b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


--
Matt Martz
@sivel
sivel.net

Alexey Vazhnov

unread,
May 4, 2016, 8:39:06 AM5/4/16
to Ansible Project
I think what better solution for storing SSH settings (hostname, port, username, proxycommand, identityfile …) is ~/.ssh/config.

Matt Hite

unread,
May 4, 2016, 11:07:51 AM5/4/16
to ansible...@googlegroups.com
Try using "ansible_ssh_port" rather than hostname:port.



--
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 ansible-proje...@googlegroups.com.
To post to this group, send email to ansible...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages