ebu_sho
ebu_sho

Reputation: 414

Ansible inventory: how to identify hosts by port

I have set 2 servers for testing purposes, which are behind a NAT network. So I configured port forwarding to SSH port for both of them.

My inventory file looks like this:

[webservers]
example.com:12021
example.com:12121

[webservers:vars]
ansible_user=root
ansible_ssh_private_key_file=~/test/keys/id_ed25519

But Ansible only identifies one of them(whichever is first in the list). My "hack" to run ansible-playbook commands on both of them is by changing the order in the hostlist, and running the playbook twice.

So, is there any way to identify the hosts by port number, and not by hostname?

Thanks in advance.

Upvotes: 2

Views: 4566

Answers (1)

Jack
Jack

Reputation: 6158

Use any label you like:

[webservers]
server1 ansible_host=example.com ansible_port=12021
server2 ansible_host=example.com ansible_port=12121

Upvotes: 6

Related Questions