ami_pre/files.sls
author Paul Tonelli <paul.tonelli@logilab.fr>
Tue, 03 Dec 2013 15:03:52 +0100
changeset 196 13f50171c58c
parent 195 d01596003bc0
permissions -rw-r--r--
[ami_pre] automatically fill-in the hash for a custom script

resolv.conf:
    tmp_state.local_managed:
        - name: /mnt/variation/etc/resolv.conf
        - source: /etc/resolv.conf
        - require:
            - mount.mounted: mounted_variation

{% if 'ami.salt_install_script' in grains %}

#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 %}

{% 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: {{ salt_install_script }}
{% if salt_script_hash %}
    - source_hash: {{ salt_script_hash }}
{% endif %}
    - mode: 755
    - require: 
      - mount.mounted: mounted_variation
  cmd.run:
    - name: chroot /mnt/variation /tmp/salt_install
    - require: 
      - file.managed: /mnt/variation/tmp/salt_install
      - tmp_state.local_managed: resolv.conf
{% endif %}

hg_variation:
    hg.latest:
        - name: {{ grains['ami.hg_address_variation'] }}
{% else %}
        - name: {{ 'http://hg.logilab.org/users/ptonelli/salt-ami-cloud-builder/variation' }} 
{% endif %}
{% if 'ami.hg_rev_variation' in grains %}
        - rev: {{ grains['ami.hg_rev_variation'] }}
{% endif %}
        - target: /mnt/variation/srv/salt
        - require:
            - mount.mounted: mounted_variation
{% endif %}