Ansible で下記のようにアドレスが同じで中継ホストが異なるインベントリを使うとき。
prod
sv01 ansible_ssh_host=192.168.88.11
sv02 ansible_ssh_host=192.168.88.12
[all:vars]
ansible_ssh_common_args = -o "ProxyCommand ssh 192.0.2.100 -l root -W %h:%p"
stage
sv01 ansible_ssh_host=192.168.88.11
sv02 ansible_ssh_host=192.168.88.12
[all:vars]
ansible_ssh_common_args = -o "ProxyCommand ssh 192.0.2.200 -l root -W %h:%p"
control_path
のデフォルトが下記のようになっていると思うので、
control_path = %(directory)s/ansible-ssh-%%h-%%p-%%r
最初に接続した方のインベントリのホストで下記のような ControlMaster のソケットファイルが作成されて、
~/.ansible/cp/ansible-ssh-192.168.88.11-22-ore
~/.ansible/cp/ansible-ssh-192.168.88.12-22-ore
別のインベントリファイルを指定してもこのソケットファイルが使用されてしまい、誤ったホストに接続されてしまいます。
ので、下記のようにどちらかのインベントリで ControlPath を変更する必要があります(もしくは無効にする)。
sv01 ansible_ssh_host=192.168.88.11
sv02 ansible_ssh_host=192.168.88.12
[all:vars]
ansible_ssh_common_args = -o "ProxyCommand ssh 192.0.2.200 -l root -W %h:%p" -o "ControlPath ~/.ssh/stage-%h-%r"