Ansible multiple hosts behind NAT port forwarding

I have 2 servers behind NAT, so they share the same IP address, SSH service runs on two different ports. Here is my ansible inventory file.

When I run the ansible command against the inventory file, it only gets executed on one of the servers.

ansible hosts behind NAT proxy


The problem is that all the hosts have the same IP address. You need to use a unique name, so ansible can identify each host separately.

I updated the inventory file as follows to get it to work.

port4000, port4001 can be any unique name that can be used to identify the hosts. If hosts have a unique hostname, you can use it.

After the change, I can execute commands on both hosts that are behind NAT port forwarding.

ansible 2 servers with different ports behind nat

Back to Ansible

Need help with Linux Server or WordPress? We can help!

Leave a Reply

Your email address will not be published. Required fields are marked *