Search code examples
mongodbvagrantansiblemolecule

How to access from one instance to another using molecule


I'm trying to use ansible-mongodb-cluster scripts to create a mongodb cluster. I've edited hosts in order to have just a primary and a slave. I use molecule with vagrant to test it.

this is my 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

and this is hosts inventory ansible file:

[mongo_servers]
mongo1 mongod_port=27017
mongo2 mongod_port=27017

[mongod_primary]
mongo1 mongod_port=27017

[mongod_slaves]
mongo2 mongod_port=27017

the problem borns when, after primary is created and replication is activated on it, slave trying to connect to the primary:

"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"

it doesn't know mongo1 host.

Even if i add in /etc/hosts the relation

192.168.80.1 mongo1

it says me that Destination Net Unreachable

how can i solve and let every VM "see" the others in the network?

EDIT

ping goes in timeout and telnet too

EDIT2

This is traceroute

[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 ~]$ 

Solution

  • I solved adding two other configuration to the 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
    

    and

    options:
                append_platform_to_hostname: no
    

    now if i ping the other vm, they reply successfully!