old_contents: import os
  
  import testinfra.utils.ansible_runner
  
  testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner(
      os.environ['MOLECULE_INVENTORY_FILE']).get_hosts('all')
  
  # check if MongoDB is enabled and running
  def test_mongo_running_and_enabled(host):
      mongo = host.service("mongod")
      assert mongo.is_running
      assert mongo.is_enabled
  
  # check if configuration file contains the required line
  def test_config_file(File):
      config_file = File('/etc/mongod.conf')
      assert config_file.contains('bindIp: 0.0.0.0')
      assert config_file.is_file
  
  
new_contents: import os
  
  import testinfra.utils.ansible_runner
  
  testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner(
      os.environ['MOLECULE_INVENTORY_FILE']).get_hosts('all')
  
  # check if MongoDB is listen concrete host and port
  def test_mongo_host_port(host):
      socket = host.socket("tcp://127.0.0.1:27017")
      assert socket.is_listening
  
  # check if MongoDB is enabled and running
  def test_mongo_running_and_enabled(host):
      mongo = host.service("mongod")
      assert mongo.is_running
      assert mongo.is_enabled
  
  # check if configuration file contains the required line
  def test_config_file(File):
      config_file = File('/etc/mongod.conf')
      assert config_file.contains('bindIp: 0.0.0.0')
      assert config_file.is_file
  
  
subject: Add 'testinfra' test method 'test_mongo_host_port'