Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ansible is connecting to the wrong hosts when using jump host

Tags:

ansible

I am managing hosts in two different data centers. I get to the managed hosts via a jump host. There is a dedicated jump host for each data center. My inventory files look something like:

$ cat inventory-dc1
[all:vars]
ansible_ssh_common_args='-o ProxyCommand="ssh -W %h:%p -q [email protected]"'

[docker]
docker-1 ansible_host=192.168.1.1
docker-2 ansible_host=192.168.1.2

$ cat inventory-dc2
[all:vars]
ansible_ssh_common_args='-o ProxyCommand="ssh -W %h:%p -q [email protected]"'

[docker]
docker-1 ansible_host=192.168.1.1
docker-2 ansible_host=192.168.1.2

When I run a playbook with inventory-dc1 everything works as expected.

The problem manifests when I subsequently run a playbook with inventory-dc2. Ansible connects to the hosts from inventory-dc1 instead of inventory-dc2. I know that the managed hosts have the same IP addesses but they are accessed via different jump hosts.

like image 371
jreisinger Avatar asked Oct 26 '25 14:10

jreisinger


1 Answers

Make unique control path for each inventory:

[all:vars]
ansible_ssh_common_args='-o ProxyCommand="ssh -W %h:%p -q [email protected]" -o ControlMaster=auto -o ControlPersist=60s -o ControlPath=~/.ansible/cp/dc1-ssh-%C'

Note dc1 prefix for path. Specify dc2 for the second inventory.

like image 170
Konstantin Suvorov Avatar answered Oct 29 '25 07:10

Konstantin Suvorov



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!