fix: safely remove legacy docker.list on Debian without unsupported args/filters

This commit is contained in:
Nk-dir 2025-10-08 18:45:21 +00:00
parent b40ecc1a3e
commit e0a31076b3

View File

@ -21,25 +21,18 @@
ansible.builtin.stat:
path: "/etc/apt/sources.list.d/docker.list"
register: legacy_docker_list
- name: Check whether legacy docker.list references the official Docker repo
ansible.builtin.command:
cmd: grep -q "{{ docker_repo_url }}" /etc/apt/sources.list.d/docker.list
register: legacy_grep
ignore_errors: true
changed_when: false
- name: Remove legacy docker.list if it does not reference the official Docker repo
ansible.builtin.shell: |
legacy_path="/etc/apt/sources.list.d/docker.list"
if [ -f "$legacy_path" ]; then
if grep -q "{{ docker_repo_url }}" "$legacy_path"; then
# file points to official repo; leave it
exit 0
else
rm -f "$legacy_path"
exit 0
fi
fi
when: legacy_docker_list.stat.exists
changed_when: "'removed' in ansible_facts.get('cmd', {}) or (legacy_docker_list.stat.exists and (lookup('file', '/etc/apt/sources.list.d/docker.list') | default('') | search(docker_repo_url) == False))"
args:
warn: false
register: remove_legacy_result
failed_when: false
ansible.builtin.file:
path: "/etc/apt/sources.list.d/docker.list"
state: absent
when: legacy_docker_list.stat.exists and legacy_grep.rc != 0
- name: Ensure dependencies are installed.
ansible.builtin.apt: