.. versionchanged:: 2015.8.11,2016.3.2
        On masterless minions, pillar modules are now synced, and refreshed
        when ``refresh`` is set to ``True``.

    Sync down all of the dynamic modules from the file server for a specific
    environment. This function synchronizes custom modules, states, beacons,
    grains, returners, output modules, renderers, and utils.

    refresh : True
        Also refresh the execution modules and recompile pillar data available
        to the minion. This refresh will be performed even if no new dynamic
        modules are synced. Set to ``False`` to prevent this refresh.

    .. important::

        If this function is executed using a :py:func:`module.run
        <salt.states.module.run>` state, the SLS file will not have access to
        newly synced execution modules unless a ``refresh`` argument is
        added to the state, like so:

        .. code-block:: yaml

            load_my_custom_module:
              module.run:
                - name: saltutil.sync_all
                - refresh: True

        See :ref:`here <reloading-modules>` for a more detailed explanation of
        why this is necessary.

    extmod_whitelist : None
        dictionary of modules to sync based on type

    extmod_blacklist : None
        dictionary of modules to blacklist based on type

    CLI Examples:

    .. code-block:: bash

        salt '*' saltutil.sync_all
        salt '*' saltutil.sync_all saltenv=dev
        salt '*' saltutil.sync_all saltenv=base,dev
        salt '*' saltutil.sync_all extmod_whitelist={'modules': ['custom_module']}

def sync_all(saltenv=None, refresh=True, extmod_whitelist=None, extmod_blacklist=None):
    '''
    .. versionchanged:: 2015.8.11,2016.3.2
        On masterless minions, pillar modules are now synced, and refreshed
        when ``refresh`` is set to ``True``.

    Sync down all of the dynamic modules from the file server for a specific
    environment. This function synchronizes custom modules, states, beacons,
    grains, returners, output modules, renderers, and utils.

    refresh : True
        Also refresh the execution modules and recompile pillar data available
        to the minion. This refresh will be performed even if no new dynamic
        modules are synced. Set to ``False`` to prevent this refresh.

    .. important::

        If this function is executed using a :py:func:`module.run
        <salt.states.module.run>` state, the SLS file will not have access to
        newly synced execution modules unless a ``refresh`` argument is
        added to the state, like so:

        .. code-block:: yaml

            load_my_custom_module:
              module.run:
                - name: saltutil.sync_all
                - refresh: True

        See :ref:`here <reloading-modules>` for a more detailed explanation of
        why this is necessary.

    extmod_whitelist : None
        dictionary of modules to sync based on type

    extmod_blacklist : None
        dictionary of modules to blacklist based on type

    CLI Examples:

    .. code-block:: bash

        salt '*' saltutil.sync_all
        salt '*' saltutil.sync_all saltenv=dev
        salt '*' saltutil.sync_all saltenv=base,dev
        salt '*' saltutil.sync_all extmod_whitelist={'modules': ['custom_module']}
    '''
    log.debug('Syncing all')
    ret = {}
    ret['clouds'] = sync_clouds(saltenv, False, extmod_whitelist, extmod_blacklist)
    ret['beacons'] = sync_beacons(saltenv, False, extmod_whitelist, extmod_blacklist)
    ret['modules'] = sync_modules(saltenv, False, extmod_whitelist, extmod_blacklist)
    ret['states'] = sync_states(saltenv, False, extmod_whitelist, extmod_blacklist)
    ret['sdb'] = sync_sdb(saltenv, extmod_whitelist, extmod_blacklist)
    ret['grains'] = sync_grains(saltenv, False, extmod_whitelist, extmod_blacklist)
    ret['renderers'] = sync_renderers(saltenv, False, extmod_whitelist, extmod_blacklist)
    ret['returners'] = sync_returners(saltenv, False, extmod_whitelist, extmod_blacklist)
    ret['output'] = sync_output(saltenv, False, extmod_whitelist, extmod_blacklist)
    ret['utils'] = sync_utils(saltenv, False, extmod_whitelist, extmod_blacklist)
    ret['log_handlers'] = sync_log_handlers(saltenv, False, extmod_whitelist, extmod_blacklist)
    ret['proxymodules'] = sync_proxymodules(saltenv, False, extmod_whitelist, extmod_blacklist)
    ret['engines'] = sync_engines(saltenv, False, extmod_whitelist, extmod_blacklist)
    ret['thorium'] = sync_thorium(saltenv, False, extmod_whitelist, extmod_blacklist)
    ret['serializers'] = sync_serializers(saltenv, False, extmod_whitelist, extmod_blacklist)
    ret['matchers'] = sync_matchers(saltenv, False, extmod_whitelist, extmod_blacklist)
    ret['executors'] = sync_executors(saltenv, False, extmod_whitelist, extmod_blacklist)
    if __opts__['file_client'] == 'local':
        ret['pillar'] = sync_pillar(saltenv, False, extmod_whitelist, extmod_blacklist)
    if refresh:
        refresh_modules()
        refresh_pillar()
    return ret