Deploy the MongoDB Replica set using Ansible.
Make sure to add hosts entries in /etc/hosts in all mongod instance. Verify whether it's reachable, i.e within network. Check it with ping or telnet. ping hostname/ip telnet hostname/ip mongo_port Quick guide
Adjust the hosts details in inventory. Adjust the global variables in group_vars/all