2

In SSH config, you can use the following format to list multiple aliases that all specify the same host:

Host DEV-USA-BGW100 dev-usa-bgw100 USA100 usa100
    HostName 192.168.1.100
    User ansible

Host DEV-CAN-BGW101 dev-can-bgw101 CAN101 can101
    HostName 192.168.2.101
    User ansible

Host DEV-CAN-BGW102 dev-can-bgw102 CAN102 can102
    HostName 192.168.2.102
    User ansible

I would like to be able to do the same thing in ansible, but I'm unsure if it's possible. The reason is I sometimes want to test a single command on a single host without typing the entire proper hostname verbatim.

I've been searching around but haven't been able to find an answer. I did find a page that says that by default, ansible will use OpenSSH on the server, and thus should read the SSH config file. I tested this, but it didn't work.

1
  • I had asked the same question in #ansible on freenode a while back. The answer was no.
    – Zoredache
    Jul 31, 2018 at 5:24

1 Answer 1

2

Define an inventory file or script that returns fully qualified host names. Then use patterns.

ansible '*can*101*' -m ping

Or, you can have groups of groups in inventory deep enough where the group name is an alias for 1 or 2 devices.

Defining the same host by different names in inventory may result in tasks being done twice to the same device.

SSH config is a separate name resolution thing Ansible is not aware of.

1
  • I totally forgot about patterns, which will be useful. I decided to take the time to try to create a bunch of nested groups to be able to account for the majority of these aliases. Thanks!
    – Damian T.
    Jul 31, 2018 at 19:35

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .