]> git.phdru.name Git - ansible.git/commitdiff
Feat(debian/clean-apt): Speed up using `find ... -delete`
authorOleg Broytman <phd@phdru.name>
Sun, 28 Dec 2025 16:34:08 +0000 (19:34 +0300)
committerOleg Broytman <phd@phdru.name>
Sun, 28 Dec 2025 23:40:11 +0000 (02:40 +0300)
playbooks/debian/clean-apt.sh [new file with mode: 0755]
playbooks/debian/clean-apt.yaml

diff --git a/playbooks/debian/clean-apt.sh b/playbooks/debian/clean-apt.sh
new file mode 100755 (executable)
index 0000000..f155206
--- /dev/null
@@ -0,0 +1,13 @@
+#! /bin/sh
+
+LC_CTYPE=en_US.UTF-8 hosts="`\"$HOME\"/.virtualenvs/ansible/bin/ansible --list-hosts servers | tail -n +2`"
+
+echo localhost
+sudo apt-get clean
+sudo find /var/lib/apt/lists -maxdepth 1 -type f \! -name lock -delete
+
+for host in $hosts; do
+   echo $host
+   ssh $host "sudo apt-get clean; exec sudo find /var/lib/apt/lists
+       -maxdepth 1 -type f \! -name lock -delete"
+done
index 8e80033f5f6e52209a68dc3e5da494df77e479c3..fdbd0a95c67cc1097a8fb19f7366d57a8175e7ad 100644 (file)
@@ -7,17 +7,5 @@
       apt:
         clean: true
 
-    - name: Find apt files
-      find:
-        paths: /var/lib/apt/lists
-        patterns: '*'
-        excludes: lock
-        depth: 1
-      register: apt_list
-    - name: Clean apt files
-      file:
-        path: "{{ item.path }}"
-        state: absent
-      with_items: "{{ apt_list.files }}"
-      loop_control:
-        label: "{{ item.path }}"
+    - name: Remove apt files
+      command: find /var/lib/apt/lists -maxdepth 1 -type f ! -name lock -delete