如何使用分子从一个实例访问另一个实例

How to access from one instance to another using molecule

我正在尝试使用 ansible-mongodb-cluster 脚本创建 mongodb 集群。 我编辑了主机以便只有一个主主机和一个从主机。 我用molecule with vagrant来测试一下。

这是我的 molecule.yml

ansible:
  playbook: 01_create_cluster.yml
  verbose: vvv
inventory: hosts
vagrant:
  platforms:
    - name: centos
      box: centos/7
  providers:
    - name: virtualbox
      type: virtualbox
      options:
        memory: 512
        cpus: 2
  instances:
    - name: mongo1
      ansible_groups:
        - mongo_servers
        - mongod_primary
        - mongod_slaves
      interfaces:
        - network_name: private_network
          type: static
          ip: 192.168.80.1
    - name: mongo2
      ansible_groups:
        - mongo_servers
        - mongod_primary
        - mongod_slaves
      interfaces:
        - network_name: private_network
          type: static
          ip: 192.168.80.2

这是 hosts 清单 ansible 文件:

[mongo_servers]
mongo1 mongod_port=27017
mongo2 mongod_port=27017

[mongod_primary]
mongo1 mongod_port=27017

[mongod_slaves]
mongo2 mongod_port=27017

当创建主节点并在其上激活复制后,从尝试连接到主节点时出现问题:

"MongoDB shell version v3.4.4", 
        "connecting to: mongodb://mongo1:27017/", 
        "2017-05-25T15:38:51.399+0000 I NETWORK  [thread1] getaddrinfo(\"mongo1\") failed: Name or service not known", 
        "2017-05-25T15:38:51.400+0000 E QUERY    [thread1] Error: couldn't initialize connection to host mongo1, address is invalid :", 
        "connect@src/mongo/shell/mongo.js:237:13", 
        "@(connect):1:6"

它不知道 mongo1 主机。

即使我添加 /etc/hosts 关系

192.168.80.1 mongo1

它说我 Destination Net Unreachable

我如何解决并让网络中的每个 VM "see" 其他人?

编辑

ping 超时,telnet 也超时

EDIT2

这是跟踪路由

[vagrant@mongo2 ~]$ traceroute mongo1
traceroute to mongo1 (192.168.80.1), 30 hops max, 60 byte packets
 1  gateway (10.0.2.2)  0.191 ms  0.111 ms  0.063 ms
 2  192.168.93.254 (192.168.93.254)  0.614 ms  0.716 ms  0.710 ms
 3  10.17.254.1 (10.17.254.1)  3.410 ms  3.366 ms  3.316 ms
 4  93-57-16-193.ip162.fastwebnet.it (93.57.16.193)  5.409 ms  5.384 ms  5.340 ms
 5  93-54-33-65.ip127.fastwebnet.it (93.54.33.65)  21.192 ms  21.135 ms  21.084 ms
 6  10.2.7.101 (10.2.7.101)  10.390 ms  2.447 ms  2.318 ms
 7  10.254.20.77 (10.254.20.77)  2.228 ms 10.254.20.73 (10.254.20.73)  2.171 ms  2.045 ms
 8  * * *
 9  * * *
10  * * *
11  * * *
12  * * *
13  * * *
14  * * *
15  * * *
16  * * *
17  * * *
18  * * *
19  * * *
20  * * *
21  * * *
22  * * *
23  * * *
24  * * *
25  * * *
26  * * *
27  * * *
28  * * *
29  * * *
30  * * *
[vagrant@mongo2 ~]$ 

我解决了向 molecule.yml 添加另外两个配置的问题:

interfaces:
        - network_name: private_network
          type: static
          ip: 192.168.80.1
          auto_config: true
      options:
        append_platform_to_hostname: no


auto_config: true

options:
            append_platform_to_hostname: no

现在,如果我 ping 其他虚拟机,他们会成功回复!