简体   繁体   English

Ansible多个主机端口转发

[英]Ansible multiple hosts with port forwarding

I have hosts inventory with multiple hosts each with port forwarding, Hosts file is : 我有多个主机的主机库存,每个主机都有端口转发,主机文件是:

[all]

10.80.238.11:20003

10.80.238.11:20001

10.80.238.11:20007

10.80.238.11:20009

I am trying to ping them with a playbook, but always get response from first entry in this case 10.80.238.11:20003 not from others. 我试图用剧本ping它们,但总是得到第一次录入的回复10.80.238.11:20003不是来自其他人。 Authentication is on place, whatever host I move to first place I get response from it but not others, my playbook is: 身份验证已经到位,无论我移动到第一个位置的主机我都得到了响应而不是其他人,我的剧本是:

---
- hosts: all

  remote_user: root

  gather_facts: no

  tasks:

  - name: test connection

    ping:

Any idea how to fix this??? 知道怎么解决这个???

I suppose that the port forwarding you're doing is for SSH. 我想您正在进行的端口转发是针对SSH的。

So you have to tell ansible which ssh port to connect to. 所以你必须告诉ansible要连接哪个ssh端口。 The problem is that all your hosts have the same IP. 问题是所有主机都具有相同的IP。 So you have to use hostnames, so Ansible can distinguish them. 所以你必须使用主机名,所以Ansible可以区分它们。

Let's assume that you refer to host with SSH port forwarded to 2000X as hostX , then the right syntax to specify ssh port along with the host IP is : 假设您将具有SSH端口的主机转发到2000X作为hostX ,然后使用正确的语法指定ssh端口以及主机IP:

host3 ansible_ssh_port=20003 ansible_ssh_host=10.80.238.11
host1 ansible_ssh_port=20001 ansible_ssh_host=10.80.238.11
host7 ansible_ssh_port=20007 ansible_ssh_host=10.80.238.11
host9 ansible_ssh_port=20009 ansible_ssh_host=10.80.238.11

You can then issue : 然后你可以发出:

ansible host3 -m ping 

or even : 甚至 :

ansible all -m ping

Note that you should not create an all group since Ansible creates it automagically. 请注意,您不应创建all组,因为Ansible会自动创建它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM