Docker - completely delete /var/lib/apt/lists when creating image #309
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
When
ansible.builtin.apt
is run with acache_valid_time
it will not do anapt update
before attempting to install a package if the cache was recently updated.It does this by first checking to see if
/var/lib/apt/periodic/update-success-stamp
exists and, if so, uses its last modified time to compare againstnow - cache_valid_time
. I believe this file is only created ifupdate-notifier-common
is installed and ran a periodic update check so isn't directly relevant here.However, if the above file doesn't exist, the ansible apt task then falls back to looking at the last modified time of
/var/lib/apt/lists
to work out if the cache has been updated recently. See https://github.com/ansible/ansible/blob/0aa8afbaf4739510a96c9727237792a95c8855c3/lib/ansible/modules/apt.py#L1174If the docker driver builds a container and then molecule runs an apt task to install a package with a
cache_valid_time
set, it'll error out stating the package isn't available because it believes the cache is up to date, but it has been removed.By deleting the whole lists directory, the task will, the first time, realise it needs to run an update first (and subsequent tasks will be able to make use of the recently retrieved cache for speed).
I've checked, and removing the whole directory seems fine; apt recreates it when you next run apt update.