[ami_pre] do not hardcode the update behavior for different distributions in SACB (closes #249331)
authorPaul Tonelli <paul.tonelli@logilab.fr>
Tue, 03 Dec 2013 11:25:25 +0100
changeset 185 ca037e9e657c
parent 184 abef89248f10
child 186 2b3c7010e3ae
[ami_pre] do not hardcode the update behavior for different distributions in SACB (closes #249331) Remove all the code doing the updates and the salt-minion install from SACB and instead provide a script in the user-data to do this tricky part. The user can now either provide a base image with salt or provide a script that will install salt on this image.
ami_pre/files.sls
scripts/centos_logilab.sh
scripts/debian.sh
scripts/debian_logilab.sh
scripts/ubuntu.sh
scripts/ubuntu_logilab.sh
user_data.cfg.sample
--- a/ami_pre/files.sls	Tue Nov 26 13:57:52 2013 +0100
+++ b/ami_pre/files.sls	Tue Dec 03 11:25:25 2013 +0100
@@ -1,98 +1,3 @@
-{% set default_address =
-'http://hg.logilab.org/users/ptonelli/salt-ami-cloud-builder/variation' %}
-
-{% if 'ami.type' not in grains or grains['ami.type'] in ('ubuntu', 'debian') %}
-{% if 'keystone.user' in grains %}
-
-
-01proxy:
-    file.managed:
-        - name: /mnt/variation/etc/apt/apt.conf.d/01proxy
-        - source: salt://others/01proxy
-        - mode: 644
-        - require:
-            - mount.mounted: mounted_variation
-{% endif %}
-
-02confold:
-    file.managed:
-        - name: /mnt/variation/etc/apt/apt.conf.d/02confold
-        - source: salt://others/02confold
-        - mode: 644
-        - require:
-            - mount.mounted: mounted_variation
-
-policy-rc.d:
-    file.managed:
-        - name: /mnt/variation/usr/sbin/policy-rc.d
-        - source: salt://others/policy-rc.d
-        - mode: 755
-        - require:
-            - mount.mounted: mounted_variation
-
-chroot_apt_get_update:
-    module.run:
-        - name: chroot.run
-        - path: /mnt/variation
-        - command: apt-get update
-        - require:
-            - tmp_state.local_managed: resolv.conf
-            - file.managed: policy-rc.d
-            - file.managed: 02confold
-{% if 'ami.type' not in grains or grains['ami.type'] == 'ubuntu' %}
-            - cmd.run: salt_ppa
-{% endif %}
-{% if 'ami.type' in grains and grains['ami.type'] == 'debian' %}
-            - file.managed: backports.list
-{% endif %}
-
-chroot_install_salt:
-    module.run:
-        - name: chroot.run
-        - path: /mnt/variation
-        - command: apt-get --force-yes -y install salt-minion python-apt
-        - require:
-            - module.run: chroot_apt_get_update
-{% endif %}
-
-{% if 'ami.type' not in grains or grains['ami.type'] == 'ubuntu' %}
-salt_ppa:
-    cmd.run:
-        - name: chroot /mnt/variation add-apt-repository ppa:saltstack/salt -y
-        - require:
-            - mount.mounted: mounted_variation
-            - mount.mounted: chroot_proc 
-            - mount.mounted: chroot_devpts
-            - tmp_state.local_managed: resolv.conf
-{% endif %}
-
-{% if 'ami.type' in grains and grains['ami.type'] == 'debian' %}
-backports.list:
-    file.managed:
-        - name: /mnt/variation/etc/apt/sources.list.d/backports.list
-        - source: salt://others/backports.list
-        - mode: 644
-        - require:
-            - mount.mounted: mounted_variation
-
-{% endif %}
-
-{% if 'ami.type' in grains and grains['ami.type'] == 'centos5' %}
-download_epel:
-    cmd.run:
-        - name:
-             chroot /mnt/variation /usr/bin/curl http://dl.fedoraproject.org/pub/epel/5/x86_64/epel-release-5-4.noarch.rpm -o /root/epel-release-5-4.noarch.rpm ;
-             chroot /mnt/variation /bin/rpm -Uvh /root/epel-release-5-4.noarch.rpm ;
-             chroot /mnt/variation /usr/bin/yum -y install mercurial salt-minion
-        - require:
-            - mount.mounted: mounted_variation
-            - mount.mounted: chroot_proc
-            - mount.mounted: chroot_devpts
-            - tmp_state.local_managed: resolv.conf
-        - unless : '[ -a /mnt/variation/usr/bin/hg ]'
-{% endif %}
-
-
 resolv.conf:
     tmp_state.local_managed:
         - name: /mnt/variation/etc/resolv.conf
@@ -100,25 +5,37 @@
         - require:
             - mount.mounted: mounted_variation
 
+
+{% 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_hash: {{ grains['ami.salt_install_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 %}
+
+
+{% if 'ami.hg_address_variation' in grains %}
 hg_variation:
     hg.latest:
-{% if 'ami.hg_address_variation' in grains %}
         - name: {{ grains['ami.hg_address_variation'] }}
-{% else %}
-        - name: {{ default_address }} 
-{% 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 %}
 
-{% if 'ami.hg_address_variation' not in grains %}
-ami.hg_address_variation:
-  grains.present:
-    - value: {{ default_address }} 
-{% endif %}
 
 {% if 'ami.hg_rev_variation' not in grains %}
 ami.hg_rev_variation:
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/scripts/centos_logilab.sh	Tue Dec 03 11:25:25 2013 +0100
@@ -0,0 +1,7 @@
+#!/bin/bash
+
+/usr/bin/curl http://dl.fedoraproject.org/pub/epel/5/x86_64/epel-release-5-4.noarch.rpm -o /root/epel-release-5-4.noarch.rpm
+
+/bin/rpm -Uvh /root/epel-release-5-4.noarch.rpm
+
+/usr/bin/yum -y install mercurial salt-minion
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/scripts/debian.sh	Tue Dec 03 11:25:25 2013 +0100
@@ -0,0 +1,24 @@
+#!/bin/bash
+
+cat << EOF > /etc/apt/apt.conf.d/02confold
+Dpkg::Options {
+    "--force-confdef";
+    "--force-confold";
+}
+EOF
+
+cat << EOF > /usr/sbin/policy-rc.d
+#!/bin/sh
+exit 101
+EOF
+
+chmod 0755 /usr/sbin/policy-rc.d
+
+cat << EOF > /etc/apt/sources.list.d/backports.list
+deb http://http.debian.net/debian/ wheezy-backports main
+deb-src http://http.debian.net/debian/ wheezy-backports main
+EOF
+
+apt-get update
+apt-get -t wheezy-backports --force-yes -y install salt-minion python-apt
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/scripts/debian_logilab.sh	Tue Dec 03 11:25:25 2013 +0100
@@ -0,0 +1,26 @@
+#!/bin/bash
+
+cat 'Acquire::http::Proxy "http://proxy.logilab.priv:3142/";' > /etc/apt/apt.conf.d/01proxy
+
+cat << EOF > /etc/apt/apt.conf.d/02confold
+Dpkg::Options {
+    "--force-confdef";
+    "--force-confold";
+}
+EOF
+
+cat << EOF > /usr/sbin/policy-rc.d
+#!/bin/sh
+exit 101
+EOF
+
+chmod 0755 /usr/sbin/policy-rc.d
+
+cat << EOF > /etc/apt/sources.list.d/backports.list
+deb http://http.debian.net/debian/ wheezy-backports main
+deb-src http://http.debian.net/debian/ wheezy-backports main
+EOF
+
+
+apt-get update
+apt-get -t wheezy-backports --force-yes -y install salt-minion python-apt python-git
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/scripts/ubuntu.sh	Tue Dec 03 11:25:25 2013 +0100
@@ -0,0 +1,20 @@
+#!/bin/bash
+
+cat << EOF > /etc/apt/apt.conf.d/02confold
+Dpkg::Options {
+    "--force-confdef";
+    "--force-confold";
+}
+EOF
+
+cat << EOF > /usr/sbin/policy-rc.d
+#!/bin/sh
+exit 101
+EOF
+
+chmod 0755 /usr/sbin/policy-rc.d
+
+add-apt-repository ppa:saltstack/salt -y
+
+apt-get update
+apt-get --force-yes -y install salt-minion python-apt
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/scripts/ubuntu_logilab.sh	Tue Dec 03 11:25:25 2013 +0100
@@ -0,0 +1,22 @@
+#!/bin/bash
+
+cat 'Acquire::http::Proxy "http://proxy.logilab.priv:3142/";' > /etc/apt/apt.conf.d/01proxy
+
+cat << EOF > /etc/apt/apt.conf.d/02confold
+Dpkg::Options {
+    "--force-confdef";
+    "--force-confold";
+}
+EOF
+
+cat << EOF > /usr/sbin/policy-rc.d
+#!/bin/sh
+exit 101
+EOF
+
+chmod 0755 /usr/sbin/policy-rc.d
+
+add-apt-repository ppa:saltstack/salt -y
+
+apt-get update
+apt-get --force-yes -y install salt-minion python-apt
--- a/user_data.cfg.sample	Tue Nov 26 13:57:52 2013 +0100
+++ b/user_data.cfg.sample	Tue Dec 03 11:25:25 2013 +0100
@@ -1,24 +1,31 @@
 #salt-grains #interpreter flag
-### necessary unless you want the standard image ###
+### necessary in most cases ###
 ami.hg_address_variation: http://hg.logilab.org/users/ptonelli/salt-ami-cloud-builder/variation
 ami.hg_rev_variation: 9ed741a55f17 #optionnal
 ami.name: my_variation
-ami.type: ubuntu #or debian
 
 ami.source_address: http://cloud-images.ubuntu.com/precise/current/precise-server-cloudimg-amd64.tar.gz
 ami.source_hash: 'md5=1d72ed9c56abb899be02e7cae0822f1d'
 
-### optionnal if your image uses existing kernel/ramdisk id in openstack ###
+
+### optional script to install salt on the machine ###
+ami.salt_install_script: http://bootstrap.saltstack.org #or another script to install salt for your distribution and maybe modify the default repositories addresses
+ami.salt_install_hash: 'md5=e7459dbb0bcd9ceeaf00712e19066475' #necessary for the salt_install_script
+
+### optional or use a provided script ###
+ami.salt_install_script: salt://scripts/debian.sh 
+
+### optional if your image uses existing kernel/ramdisk id in openstack ###
 kernel_id:a5b900bd-c009-40b2-a763-32b32996b1ee
 initrd_id:b953e40a-2605-402b-8663-c8556a5899f2
 
-### optionnal (ami_creation code update), do not enable unless you know what you are doing ###
+### optional (ami_creation code update), do not enable unless you know what you are doing ###
 ami.hg_address_server: http://hg.logilab.org/master/salt-ami-cloud-builder/
 
 ### if you need to create an image bigger than 3Gb, please specify the free space necessary
 ami.image_size: 6G
 
-### optionnal (necessary to upload to openstack) ###
+### optional (necessary to upload to openstack) ###
 ### these information can be found in the file downloaded from openstack web interface
 ### This file is available in "settings", "OpenStack Credentials", download.
 ### You should be able to fit the following paramaters easily
@@ -29,7 +36,7 @@
 keystone.auth_url: 'http://control.example.com:5000/v2.0'
 keystone.insecure: False   #(optional)
 
-### optionnal (necessary to upload to amazon aws) ###
+### optional (necessary to upload to amazon aws) ###
 ### You need to create your own private key and certificate for openstack first. ###
 ### remove the BEGIN and END statements found in the files ###
 ### do not forget the ' ' at each newline for ConfigParser ###