[ami_pre] add the possible methods to install salt
authorPaul Tonelli <paul.tonelli@logilab.fr>
Tue, 03 Dec 2013 12:06:16 +0100
changeset 195 d01596003bc0
parent 194 556257e07714
child 196 13f50171c58c
[ami_pre] add the possible methods to install salt - provide a ami.distribution='ubuntu' parameter in the user data: the script will get the corresponding script in ami-builder if possible - provide a ami.salt_install_script='http://...': requires a salt_script_hash parameter with the correct syntax (it will be used by file.managed) - do not provide anything: the bootstrap salt script will be used, this is NOT a good idea from a security point of view, but offers a default solution when nothing else is available
ami_pre/files.sls
--- a/ami_pre/files.sls	Tue Dec 03 11:24:39 2013 +0100
+++ b/ami_pre/files.sls	Tue Dec 03 12:06:16 2013 +0100
@@ -6,10 +6,28 @@
             - mount.mounted: mounted_variation
 
 {% if 'ami.salt_install_script' in grains %}
+
+#use a script adress
+{% set salt_install_script = grains['ami.salt_install_script'] %}
+
+
+{% elif 'ami.distribution' in grains %}
+
+{% set salt_install_script = 'salt://script/{0}.sh'.format(grains['ami.distribution']) %}
+
+{% else %}
+
+#definitely unsafe and dirty, avoid whenever possible
+{% set salt_install_script = 'http://bootstrap.saltstack.org'  %}
+{% set salt_script_hash = 'md5={0}'.format(salt['cmd.run']('wget -O - http://bootstrap.saltstack.org|md5sum|cut -c 1-32'))  %}
+
+{% endif %}
+
+{% if 'ami.salt_install_script' in grains %}
 /mnt/variation/tmp/salt_install:
   file.managed:
-    - source: {{ grains['ami.salt_install_script'] }}
-{% if 'ami.salt_install_hash' in grains %}
+    - source: {{ salt_install_script }}
+{% if 'ami.salt_script_hash' in grains %}
     - source_hash: {{ grains['ami.salt_install_hash'] }}
 {% endif %}
     - mode: 755