Skip to content

Commit af808b2

Browse files
fix(docker) - completely delete /var/lib/apt/lists when creating image (#309)
When `ansible.builtin.apt` is run with a `cache_valid_time` it will not do an `apt 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 against `now - cache_valid_time`. I believe this file is only created if `update-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#L1174 If 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. Co-authored-by: Daniel Ziegenberg <daniel@ziegenberg.at>
1 parent 0933d2b commit af808b2

1 file changed

Lines changed: 1 addition & 1 deletion

File tree

src/molecule_plugins/docker/playbooks/Dockerfile.j2

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ ENV {{ var }} {{ value }}
1414
{% endfor %}
1515
{% endif %}
1616

17-
RUN if [ $(command -v apt-get) ]; then export DEBIAN_FRONTEND=noninteractive && apt-get update && apt-get install -y python3 sudo bash ca-certificates iproute2 python3-apt aptitude rsync && apt-get clean && rm -rf /var/lib/apt/lists/*; \
17+
RUN if [ $(command -v apt-get) ]; then export DEBIAN_FRONTEND=noninteractive && apt-get update && apt-get install -y python3 sudo bash ca-certificates iproute2 python3-apt aptitude rsync && apt-get clean && rm -rf /var/lib/apt/lists; \
1818
elif [ $(command -v dnf) ]; then dnf makecache && dnf --assumeyes install /usr/bin/python3 /usr/bin/python3-config /usr/bin/dnf-3 sudo bash iproute rsync && dnf clean all; \
1919
elif [ $(command -v yum) ]; then yum makecache fast && yum install -y /usr/bin/python /usr/bin/python2-config sudo yum-plugin-ovl bash iproute rsync && sed -i 's/plugins=0/plugins=1/g' /etc/yum.conf && yum clean all; \
2020
elif [ $(command -v zypper) ]; then zypper refresh && zypper install -y python3 sudo bash iproute2 rsync && zypper clean -a; \

0 commit comments

Comments
 (0)