home · contact · privacy
Ansible script: Try a more idempotent approach for package clearing.
authorChristian Heller <c.heller@plomlompom.de>
Fri, 14 Apr 2017 22:10:36 +0000 (00:10 +0200)
committerChristian Heller <c.heller@plomlompom.de>
Fri, 14 Apr 2017 22:10:36 +0000 (00:10 +0200)
ansible/config.yml
ansible/files/apt-mark/manual [new file with mode: 0644]
ansible/files/apt-mark/required [new file with mode: 0644]
ansible/files/apt-mark/required-plus [new file with mode: 0644]

index ec592c674b9d8e4d73d19e32fdb2a99a4a409d2e..5e7503b64b51d5e56c3af2f5575c73d7136d0ee0 100644 (file)
   # Configure package management.
   - name: update package lists
     apt: update_cache=yes
-  - name: check for initial_purge_happened flag
-    stat: path=flags/initial_purge_happened
-    register: initial_purge
-  - name: perform initial purge
-    include: tasks/initial_purge.yml
-    when: initial_purge.stat.exists == False
+  #- name: check for initial_purge_happened flag
+  #  stat: path=flags/initial_purge_happened
+  #  register: initial_purge
+  #- name: perform initial purge
+  #  include: tasks/initial_purge.yml
+  #  when: initial_purge.stat.exists == False
   - name: APT - dist-upgrade
     apt: upgrade=dist
 
@@ -32,7 +32,7 @@
     shell: update-grub
 
   # Ensure power management.
-  - name: ensure newest kernel and grub are installed
+  - name: ensure power management tools are installed
     apt: name={{item}} state=present
     with_items:
     - tlp
     - xul-ext-noscript
     - xul-ext-pentadactyl
     - vim-gtk  # used by pentadactyl for text editing
+
+  # Remove undesired packages
+  - name: collect required packages
+    shell: cat files/apt-mark/* > /tmp/white_list_unsorted && sort /tmp/white_list_unsorted > /tmp/white_list_sorted
+  - name: collect currently installed packages
+    shell: dpkg-query -Wf '${Package}\n' > /tmp/all_unsorted && sort /tmp/all_unsorted > /tmp/all_sorted
+  - name: create black list of packages to mark as automatically installed from the difference between the required packages and the packages currently installed
+    shell: comm -3 /tmp/all_sorted /tmp/white_list_sorted > /tmp/list_black
+  - name: mark all packages from black list as automatically installed
+    shell: apt-mark auto $(cat /tmp/list_black)
+  - name: purge all packages automatically installed that are not depended on
+    shell: DEBIAN_FRONTEND=noninteractive apt-get -y --purge autoremove
diff --git a/ansible/files/apt-mark/manual b/ansible/files/apt-mark/manual
new file mode 100644 (file)
index 0000000..d2e1137
--- /dev/null
@@ -0,0 +1,32 @@
+acpi-call-dkms
+bumblebee-nvidia
+console-setup
+dmenu
+git
+grub2
+i3
+i3status
+iceweasel
+less
+libgl1-mesa-dri
+libglu1-mesa
+libpam-systemd
+linux-headers-amd64
+linux-image-amd64
+locales
+man-db
+manpages
+openssh-client
+primus
+redshift
+sudo
+tlp
+vim
+vim-gtk
+xinit
+x11-xserver-utils
+xserver-xorg-core
+xserver-xorg-input-evdev
+xterm
+xul-ext-noscript
+xul-ext-pentadactyl
diff --git a/ansible/files/apt-mark/required b/ansible/files/apt-mark/required
new file mode 100644 (file)
index 0000000..43afba8
--- /dev/null
@@ -0,0 +1,55 @@
+base-files
+base-passwd
+bash
+bsdutils
+coreutils
+dash
+debconf
+debianutils
+diffutils
+dpkg
+e2fslibs
+e2fsprogs
+findutils
+gcc-6-base
+grep
+gzip
+hostname
+init-system-helpers
+libacl1
+libattr1
+libblkid1
+libc6
+libc-bin
+libcomerr2
+libfdisk1
+libgcc1
+liblzma5
+libmount1
+libpam0g
+libpam-modules
+libpam-modules-bin
+libpam-runtime
+libpcre3
+libselinux1
+libsepol1
+libsmartcols1
+libss2
+libtinfo5
+libuuid1
+login
+lsb-base
+mawk
+mount
+multiarch-support
+ncurses-base
+ncurses-bin
+passwd
+perl-base
+sed
+sensible-utils
+sysvinit-utils
+tar
+tzdata
+util-linux
+zlib1g
diff --git a/ansible/files/apt-mark/required-plus b/ansible/files/apt-mark/required-plus
new file mode 100644 (file)
index 0000000..c4e6c7f
--- /dev/null
@@ -0,0 +1,3 @@
+ansible
+ifupdown
+isc-dhcp-client