[ami_pre] automatically fill-in the hash for a custom script
authorPaul Tonelli <paul.tonelli@logilab.fr>
Tue, 03 Dec 2013 15:03:52 +0100
changeset 196 13f50171c58c
parent 195 d01596003bc0
child 197 f84de149155d
[ami_pre] automatically fill-in the hash for a custom script
ami_pre/files.sls
--- a/ami_pre/files.sls	Tue Dec 03 12:06:16 2013 +0100
+++ b/ami_pre/files.sls	Tue Dec 03 15:03:52 2013 +0100
@@ -10,6 +10,14 @@
 #use a script adress
 {% set salt_install_script = grains['ami.salt_install_script'] %}
 
+#fill in the hash if necessary
+{% set salt_script_hash = '' %}
+
+{% if 'ami.salt_script_hash' in grains %}
+{% set salt_script_hash = 'md5={0}'.format(grains['ami.salt_script_hash']) %}
+{% elif not grains['ami.salt_install_script'].startswith('salt://') %}
+{% set salt_script_hash = 'md5={0}'.format(salt['cmd.run']('wget -O - {0}|md5sum|cut -c 1-32'.format(grains['ami.salt_install_script']))) %}
+{% endif %}
 
 {% elif 'ami.distribution' in grains %}
 
@@ -27,8 +35,8 @@
 /mnt/variation/tmp/salt_install:
   file.managed:
     - source: {{ salt_install_script }}
-{% if 'ami.salt_script_hash' in grains %}
-    - source_hash: {{ grains['ami.salt_install_hash'] }}
+{% if salt_script_hash %}
+    - source_hash: {{ salt_script_hash }}
 {% endif %}
     - mode: 755
     - require: