the scripts now cleans the ssh keys if present as well as the apt cache
authorPaul Tonelli <paul.tonelli@logilab.fr>
Tue, 12 Mar 2013 11:51:26 +0100
changeset 66 23a31e4cbb65
parent 65 0cba5e282f10
child 67 3ad62a5b9c17
the scripts now cleans the ssh keys if present as well as the apt cache
ami_creator_post.sls
--- a/ami_creator_post.sls	Mon Mar 11 18:29:08 2013 +0100
+++ b/ami_creator_post.sls	Tue Mar 12 11:51:26 2013 +0100
@@ -1,67 +1,92 @@
 ### Salt state to check after modifying chroot ###
 
+{% set chroot = '/mnt/variation' %}
 ### deletes ###
 
-policy:
-    file.absent:
-        - name: /mnt/variation/usr/sbin/policy-rc.d
-
 #01proxy:
 #    file.absent:
-#        - name: /mnt/variation/etc/apt/apt.conf.d/01proxy
+#        - name: {{ chroot }}/etc/apt/apt.conf.d/01proxy
 
 02confold:
     file.absent:
-        - name: /mnt/variation/etc/apt/apt.conf.d/02confold
+        - name: {{ chroot }}/etc/apt/apt.conf.d/02confold
 
 resolv.conf:
     file.absent:
-        - name: /mnt/variation/etc/resolv.conf
+        - name: {{ chroot }}/etc/resolv.conf
 
+{% set keyfiles = ['ssh_host_dsa_key', 'ssh_host_dsa_key.pub', 'ssh_host_rsa_key', 'ssh_host_rsa_key.pub'] %}
+{% for file in keyfiles %}
+ssh_host_keys_{{ file }}:
+    file.absent:
+        - name: {{ chroot }}/etc/ssh/{{ file }}
+{% endfor %}
 
-### Extract necessary files ###
+### remove apt caches ###
+{% set bin_caches = salt['file.find'](chroot + '/var/cache/apt/', iname='*bin') %}
+{% for file in bin_caches %}
+apt_cache_{{ file }}:
+    file.absent:
+        - name: {{ file }}
+{% endfor %}
 
-{% for file in salt['file.find']('/mnt/variation/boot/', iname='vmlinuz*') %}
+apt_lists:
+    file.absent:
+        - name: {{ chroot }}/var/lib/apt/lists
+
+apt_policy:
+    file.absent:
+        - name: {{ chroot }}/usr/sbin/policy-rc.d
+
+### extract necessary files ###
+
+{% for file in salt['file.find'](chroot + '/boot/', iname='vmlinuz*') %}
 kernel:
     tmp_state.local_managed:
         - name: /mnt/vmlinuz_variation
         - source: {{ file }}
 {% endfor %}
 
-{% for file in salt['file.find']('/mnt/variation/boot/', iname='initrd*') %}
+{% for file in salt['file.find'](chroot + '/boot/', iname='initrd*') %}
 initrd:
     tmp_state.local_managed:
         - name: /mnt/initrd_variation
         - source: {{ file }}
 {% endfor %}
 
-
 ### umounts ###
 umount_chroot_proc:
     tmp_state.umounted:
-        - name: /mnt/variation/proc
+        - name: {{ chroot }}/proc
 
 umount_chroot_devpts:
     tmp_state.umounted:
-        - name: /mnt/variation/dev/pts
+        - name: {{ chroot }}/dev/pts
 
 umount_chroot_slash:
     tmp_state.umounted:
-        - name: /mnt/variation
+        - name: {{ chroot }}
         - require:
             - tmp_state.umounted: umount_chroot_devpts
             - tmp_state.umounted: umount_chroot_proc
             - tmp_state.local_managed: kernel
             - tmp_state.local_managed: initrd
-            - file.absent: policy
 #            - file.absent: 01proxy_removed
             - file.absent: 02confold
             - file.absent: resolv.conf
+{% for file in keyfiles %}
+            - file.absent: ssh_host_keys_{{ file }}
+{% endfor %}
+{% for file in bin_caches %}
+            - file.absent: apt_cache_{{ file }}
+{% endfor %}
+            - file.absent: apt_lists
+            - file.absent: apt_policy
 
 ### Resize the partition to min ###
 resize_variation:
     tmp_state.resized:
-        - name: /mnt/variation.img
+        - name: {{ chroot }}.img
         - require:
             - tmp_state.unmounted: umount_chroot_slash