diff --git a/salt/modules/file.py b/salt/modules/file.py index a75b754f6f..8f0c6914b6 100644 --- a/salt/modules/file.py +++ b/salt/modules/file.py @@ -3740,16 +3740,22 @@ def get_managed( if source and (template or parsed_scheme in salt.utils.files.REMOTE_PROTOS): # Check if we have the template or remote file cached + cache_refetch = False cached_dest = __salt__['cp.is_cached'](source, saltenv) if cached_dest and (source_hash or skip_verify): htype = source_sum.get('hash_type', 'sha256') cached_sum = get_hash(cached_dest, form=htype) - if skip_verify or cached_sum == source_sum['hsum']: + if cached_sum != source_sum['hsum']: + cache_refetch = True + elif skip_verify: + # prev: if skip_verify or cached_sum == source_sum['hsum']: + # but `cached_sum == source_sum['hsum']` is elliptical as prev if sfn = cached_dest source_sum = {'hsum': cached_sum, 'hash_type': htype} # If we didn't have the template or remote file, let's get it - if not sfn: + # Similarly when the file has been updated and the cache has to be refreshed + if not sfn or cache_refetch: try: sfn = __salt__['cp.cache_file'](source, saltenv) except Exception as exc: