def METHOD_NAME(task, mongodb_restarted_hosts):
    task.update_details(
        "Checking restarted instances and executing script...", persist=True
    )
    user = password = None
    if mongodb_restarted_hosts:
        first_host = mongodb_restarted_hosts[0]
        instance = first_host.instances.first()
        infra = instance.databaseinfra
        master_ssl_ca = InfraSSLBaseName(instance).master_ssl_ca
        driver = infra.get_driver()
        user, password, _ = driver.build_new_infra_auth()
        if not user or not password:
            raise Exception("Credentials not found")
    for i, host in enumerate(mongodb_restarted_hosts):
        log = '\n{} of {} - Host {}'.format(
            i+1, len(mongodb_restarted_hosts), host
        )
        LOG.info(log)
        task.update_details(log, persist=True)
        infra = host.instances.first().databaseinfra
        if infra.ssl_mode == infra.REQUIRETLS:
            ssl_connect = '--tls --tlsCAFile {}'.format(master_ssl_ca)
        else:
            ssl_connect = ''
        script_mongodb_rotate_formated = script_mongodb_rotate % (
            ssl_connect, ssl_connect, ssl_connect
            )
        output = host.ssh.run_script(
            script=script_is_syslog,
            raise_if_error=False
        )
        if output['exit_code'] == 0:
            msg = '\nHost {}: SYSLOG'.format(host)
            LOG.info(msg)
            task.update_details(msg, persist=True)
        else:
            output = host.ssh.run_script(
                script=script_is_datalog_empty,
                raise_if_error=False
            )
            if output['exit_code'] == 0:
                msg = '\nHost {}: Writing to filer, but it needs restart.'.format(host)
                LOG.info(msg)
                task.update_details(msg, persist=True)
            else:
                output = host.ssh.run_script(
                    script=script_rotate_already_executed,
                    raise_if_error=False
                )
                if output['exit_code'] == 0:
                    msg = '\nHost {}: Rotate already updated.'.format(host)
                    LOG.info(msg)
                    task.update_details(msg, persist=True)
                else:
                    msg = '\nStarting log rotate changes.'
                    LOG.info(msg)
                    task.update_details(msg, persist=True)
                    msg = '\nRemoving old rotate file.'
                    LOG.info(msg)
                    task.update_details(msg, persist=True)
                    host.ssh.run_script(remove_log_rotate_file)
                    msg = '\nCreating new rotate scripts.'
                    LOG.info(msg)
                    task.update_details(msg, persist=True)
                    host.ssh.run_script(create_mongodb_rotate_script)
                    host.ssh.run_script(create_log_params_script)
                    host.ssh.run_script(script_mongodb_rotate_formated)
                    host.ssh.run_script(script_mongodb_log_params)
                    msg = '\nCreating profile file.'
                    LOG.info(msg)
                    task.update_details(msg, persist=True)
                    host.ssh.run_script(
                        create_profile_file.format(
                            user, password
                        )
                    )
                    msg = '\nCreating cron job.'
                    LOG.info(msg)
                    task.update_details(msg, persist=True)
                    host.ssh.run_script(add_cron_job)
                    msg = '\nHost {}: Rotate script successfully updated.'.format(host)
                    LOG.info(msg)
                    task.update_details(msg, persist=True)