Refresh ubuntu-14.04

Closes-Bug: PROD-21397 (PROD:21397)

Change-Id: I5a7717e26c016bd5a89d9cb1031dca7c14299050
diff --git a/ubuntu-16.04/http/preseed.cfg b/common/files/legacy/http/preseed.cfg
similarity index 100%
rename from ubuntu-16.04/http/preseed.cfg
rename to common/files/legacy/http/preseed.cfg
diff --git a/common/ubuntu_trusty_base.sh b/common/ubuntu_trusty_base.sh
new file mode 100644
index 0000000..f7ae78c
--- /dev/null
+++ b/common/ubuntu_trusty_base.sh
@@ -0,0 +1,74 @@
+#!/bin/bash -xe
+
+# Don't use /tmp/ - some templates do node reboot
+if [ -f /done_ubuntu_base ] ; then
+  echo "INFO: ubuntu_base already finished.Skipping.."
+  exit 0
+fi
+#
+UBUNTU_BASEURL="${UBUNTU_BASEURL:-mirror://mirrors.ubuntu.com/mirrors.txt}"
+## Base packages and setup
+export DEBIAN_FRONTEND=noninteractive
+echo -e '#!/bin/sh\nexit 101' > /usr/sbin/policy-rc.d
+chmod +x /usr/sbin/policy-rc.d
+
+# Configure apt. Please refer to
+# https://github.com/Mirantis/reclass-system-salt-model/blob/master/linux/system/single/debian.yml
+# and keep those structures with same naming convention - to prevent
+# misconfiguration between base system and salt state.
+echo "Acquire::CompressionTypes::Order gz;" >/etc/apt/apt.conf.d/99compression-workaround-salt
+echo "Acquire::EnableSrvRecords false;" >/etc/apt/apt.conf.d/99enablesrvrecords-false
+echo "Acquire::http::Pipeline-Depth 0;" > /etc/apt/apt.conf.d/99aws-s3-mirrors-workaround-salt
+echo "APT::Install-Recommends false;" > /etc/apt/apt.conf.d/99dont_install_recommends-salt
+echo "APT::Install-Suggests false;" > /etc/apt/apt.conf.d/99dont_install_suggests-salt
+echo "Acquire::Languages none;" > /etc/apt/apt.conf.d/99dont_acquire_all_languages-salt
+echo "APT::Periodic::Update-Package-Lists 0;" > /etc/apt/apt.conf.d/99dont_update_package_list-salt
+echo "APT::Periodic::Download-Upgradeable-Packages 0;" > /etc/apt/apt.conf.d/99dont_update_download_upg_packages-salt
+echo "APT::Periodic::Unattended-Upgrade 0;" > /etc/apt/apt.conf.d/99disable_unattended_upgrade-salt
+
+sysctl -w fs.file-max=100000
+# Overwrite default mirrors
+echo "deb [arch=amd64] ${UBUNTU_BASEURL} trusty main restricted universe" > /etc/apt/sources.list
+echo "deb [arch=amd64] ${UBUNTU_BASEURL} trusty-updates main restricted universe" >> /etc/apt/sources.list
+echo "deb [arch=amd64] ${UBUNTU_BASEURL} trusty-security main restricted universe" >> /etc/apt/sources.list
+echo "deb [arch=amd64] ${UBUNTU_BASEURL} trusty-backports main restricted universe" >> /etc/apt/sources.list
+
+apt-get clean
+apt-get update
+
+# Useful tools
+EXTRA_PKGS="byobu curl ethtool iputils-ping lsof strace tcpdump traceroute wget iptables"
+# Pretty tools
+EXTRA_PKGS="${EXTRA_PKGS} byobu htop tmux tree vim-nox mc"
+# Common prerequisites
+EXTRA_PKGS="${EXTRA_PKGS} apt-transport-https libmnl0 python-apt python-m2crypto python-psutil acpid"
+apt-get -y install ${EXTRA_PKGS}
+
+# Cleanup old kernels, ensure latest is installed via virtual package
+if [ ! -f /tmp/no_install_kernel ]; then
+    modprobe cpuid
+    apt-get purge -y linux-image-* linux-headers-* | grep -v 'is not installed, so not removed'
+    apt-get install -y linux-image-virtual-lts-xenial linux-image-extra-virtual-lts-xenial
+
+    # Update grub cmdline
+    sed -i 's|GRUB_CMDLINE_LINUX_DEFAULT=.*|GRUB_CMDLINE_LINUX_DEFAULT="console=tty0 console=ttyS0,115200n8"|g' /etc/default/grub
+    sed -i 's|GRUB_CMDLINE_LINUX=.*|GRUB_CMDLINE_LINUX="console=tty0 console=ttyS0,115200n8"|g' /etc/default/grub
+    update-grub
+fi
+
+apt-get -y upgrade
+apt-get -y dist-upgrade
+
+apt-get autoremove --purge
+
+# Tmux fixes
+cat << 'EOF' >> /etc/tmux.conf
+set -g default-terminal "screen-256color"
+set -g set-titles on
+set -g xterm-keys on
+EOF
+
+# Setup cloud-init
+apt-get -y install cloud-init
+
+touch /done_ubuntu_base
diff --git a/ubuntu-14.04/scripts/security.sh b/common/ubuntu_trusty_security.sh
similarity index 100%
rename from ubuntu-14.04/scripts/security.sh
rename to common/ubuntu_trusty_security.sh
diff --git a/ubuntu-14.04/config-drive/user-data.yaml b/ubuntu-14.04/config-drive/user-data.yaml
new file mode 100644
index 0000000..03ddb4a
--- /dev/null
+++ b/ubuntu-14.04/config-drive/user-data.yaml
@@ -0,0 +1,18 @@
+#cloud-config
+debug: True
+ssh_pwauth: True
+disable_root: false
+chpasswd:
+  list: |
+    root:r00tme
+#    cloud-user:ho5uo7Uome5d
+  expire: False
+output: {all: '| tee -a /var/log/cloud-init-output.log'}
+runcmd:
+  - sed -i'.orig' -e's/PermitRootLogin.*/PermitRootLogin yes/g' -e's/PasswordAuthentication.*/PasswordAuthentication yes/g' /etc/ssh/sshd_config
+  - service ssh restart
+# speed up resolving, and not stuck on timeouts. One-shot changes
+  - echo '127.0.0.1 ubuntu' >> /etc/hosts
+  - echo 'options timeout:1 attempts:4' >> /etc/resolv.conf
+  - echo 'nameserver 172.18.208.44' >> /etc/resolvconf/resolv.conf.d/base
+  - resolvconf -u
diff --git a/ubuntu-14.04/configs/cloud/cloud.cfg b/ubuntu-14.04/files/etc/cloud/cloud.cfg
similarity index 97%
rename from ubuntu-14.04/configs/cloud/cloud.cfg
rename to ubuntu-14.04/files/etc/cloud/cloud.cfg
index c3cbb03..94b618d 100644
--- a/ubuntu-14.04/configs/cloud/cloud.cfg
+++ b/ubuntu-14.04/files/etc/cloud/cloud.cfg
@@ -4,6 +4,7 @@
 
 # This will cause the set+update hostname module to not operate (if true)
 preserve_hostname: false
+apt_preserve_sources_list: true
 
 # Better let managing of /etc/hosts on salt and others
 # manage_etc_hosts: localhost
diff --git a/ubuntu-14.04/configs/cloud/cloud.cfg.d/99_tcp.cfg b/ubuntu-14.04/files/etc/cloud/cloud.cfg.d/99_tcp.cfg
similarity index 92%
rename from ubuntu-14.04/configs/cloud/cloud.cfg.d/99_tcp.cfg
rename to ubuntu-14.04/files/etc/cloud/cloud.cfg.d/99_tcp.cfg
index 2f1b85c..7fbc1c8 100644
--- a/ubuntu-14.04/configs/cloud/cloud.cfg.d/99_tcp.cfg
+++ b/ubuntu-14.04/files/etc/cloud/cloud.cfg.d/99_tcp.cfg
@@ -3,6 +3,7 @@
     Ec2:
       timeout: 5 # (defaults to 50 seconds)
       max_wait: 10 # (defaults to 120 seconds)
+      strict_id: false
     OpenStack:
       timeout: 5 # (defaults to 50 seconds)
       max_wait: 10 # (defaults to 120 seconds)
@@ -10,6 +11,9 @@
       timeout: 5 # (defaults to 50 seconds)
       max_wait: 10 # (defaults to 120 seconds)
 
+warnings:
+   dsid_missing_source: off
+
 system_info:
    # This will affect which distro class gets used
    distro: ubuntu
diff --git a/ubuntu-14.04/http/preseed-lvm.cfg b/ubuntu-14.04/http/preseed-lvm.cfg
deleted file mode 100644
index fbaf984..0000000
--- a/ubuntu-14.04/http/preseed-lvm.cfg
+++ /dev/null
@@ -1,68 +0,0 @@
-choose-mirror-bin mirror/http/proxy string
-d-i debian-installer/framebuffer boolean false
-d-i debconf/frontend select noninteractive
-d-i base-installer/kernel/override-image string linux-server
-d-i clock-setup/utc boolean true
-d-i clock-setup/utc-auto boolean true
-d-i finish-install/reboot_in_progress note
-d-i grub-installer/only_debian boolean true
-d-i grub-installer/with_other_os boolean true
-d-i netcfg/get_domain string unassigned-domain
-d-i netcfg/get_hostname string unassigned-hostname
-
-d-i partman-auto/disk string /dev/sda /dev/vda
-d-i partman-auto/method string lvm
-d-i partman-lvm/device_remove_lvm boolean true
-d-i partman-md/device_remove_md boolean true
-d-i partman-lvm/confirm boolean true
-d-i partman-lvm/confirm_nooverwrite boolean true
-
-d-i partman-auto/init_automatically_partition \
-	select Guided - use entire disk and set up LVM
-
-d-i partman-auto-lvm/guided_size string max
-d-i partman-auto-lvm/new_vg_name string vg00
-
-d-i partman-auto/expert_recipe string                         \
-      boot-root ::                                            \
-              64 128 256 ext4                                 \
-                      $primary{ } $bootable{ }                \
-                      method{ format } format{ }              \
-                      use_filesystem{ } filesystem{ ext4 }    \
-                      mountpoint{ /boot }                     \
-                      options/noatime{ noatime }              \
-              .                                               \
-              128 512 200% linux-swap                         \
-                      method{ swap } format{ } $lvmok{ }      \
-              .                                               \
-              512 512 -1 ext4                                 \
-                      method{ format } format{ } $lvmok{ }    \
-                      use_filesystem{ } filesystem{ ext4 }    \
-                      mountpoint{ / }                         \
-                      options/noatime{ noatime }              \
-              .                                               \
-
-d-i partman/default_filesystem string ext4
-
-d-i partman/confirm_write_new_label boolean true
-d-i partman/choose_partition select finish
-d-i partman/confirm boolean true
-d-i partman/confirm_nooverwrite boolean true
-
-d-i pkgsel/include string openssh-server
-d-i pkgsel/install-language-support boolean false
-d-i pkgsel/update-policy select none
-popularity-contest popularity-contest/participate boolean false
-
-d-i pkgsel/upgrade select none
-
-d-i time/zone string UTC
-d-i passwd/root-login boolean true
-d-i passwd/make-user boolean false
-d-i openssh-server/permit-root-login boolean true
-d-i user-setup/allow-password-weak boolean true
-d-i user-setup/encrypt-home boolean false
-tasksel tasksel/first multiselect minimal, ssh-server, openssh-server
-
-d-i preseed/late_command string \
-    in-target sed -i 's/PermitRootLogin.*/PermitRootLogin yes/g' /etc/ssh/sshd_config
diff --git a/ubuntu-14.04/http/preseed.cfg b/ubuntu-14.04/http/preseed.cfg
deleted file mode 100644
index f6727d3..0000000
--- a/ubuntu-14.04/http/preseed.cfg
+++ /dev/null
@@ -1,48 +0,0 @@
-choose-mirror-bin mirror/http/proxy string
-d-i debian-installer/framebuffer boolean false
-d-i debconf/frontend select noninteractive
-d-i base-installer/kernel/override-image string linux-server
-d-i clock-setup/utc boolean true
-d-i clock-setup/utc-auto boolean true
-d-i finish-install/reboot_in_progress note
-d-i grub-installer/only_debian boolean true
-d-i grub-installer/with_other_os boolean true
-d-i netcfg/get_domain string unassigned-domain
-d-i netcfg/get_hostname string unassigned-hostname
-
-d-i partman-auto/disk string /dev/sda /dev/vda
-d-i partman-auto/method string regular
-d-i partman/choose_partition select finish
-d-i partman/confirm boolean true
-d-i partman/confirm_nooverwrite boolean true
-d-i partman/confirm_write_new_label boolean true
-d-i partman-basicfilesystems/no_swap boolean false
-d-i partman-auto/choose_recipe select boot-root
-
-d-i partman-auto/expert_recipe string                   \
-    boot-root ::                                        \
-        512 512 -1 ext4                                 \
-                $primary{ } $bootable{ }                \
-                method{ format } format{ }              \
-                use_filesystem{ } filesystem{ ext4 }    \
-                mountpoint{ / }                         \
-                options/noatime{ noatime }              \
-        .                                               \
-
-d-i pkgsel/include string openssh-server 
-d-i pkgsel/install-language-support boolean false
-d-i pkgsel/update-policy select none
-popularity-contest popularity-contest/participate boolean false
-
-d-i pkgsel/upgrade select none
-
-d-i time/zone string UTC
-d-i passwd/root-login boolean true
-d-i passwd/make-user boolean false
-d-i openssh-server/permit-root-login boolean true
-d-i user-setup/allow-password-weak boolean true
-d-i user-setup/encrypt-home boolean false
-tasksel tasksel/first multiselect minimal, ssh-server, openssh-server
-
-d-i preseed/late_command string \
-    in-target sed -i 's/PermitRootLogin.*/PermitRootLogin yes/g' /etc/ssh/sshd_config
diff --git a/ubuntu-14.04/run.example.sh b/ubuntu-14.04/run.example.sh
new file mode 100755
index 0000000..2bc0641
--- /dev/null
+++ b/ubuntu-14.04/run.example.sh
@@ -0,0 +1,28 @@
+#!/bin/bash
+
+# pre-requirments:
+# apt-get install cloud-localds
+# Cloudimg: wget https://cloud-images.ubuntu.com/trusty/XXXX/trusty-server-cloudimg-amd64-disk1.img
+# Packer: https://releases.hashicorp.com/packer/1.1.3/packer_1.1.3_linux_amd64.zip
+
+# Those script - only example for variables, which should be passed to packer and
+# overwrite variables under /scripts/ directory
+
+# External script sources:
+# http/bootstrap.saltstack.com.sh https://github.com/saltstack/salt-bootstrap
+#
+export IMAGE_NAME="ubuntu-14-04-x64"
+export UBUNTU_BASEURL="http://mirror.mirantis.com/proposed/ubuntu/"
+export SALTSTACK_REPO="deb [arch=amd64] http://mirror.mirantis.com/proposed/saltstack-2017.7/trusty trusty main"
+export SALTSTACK_GPG="http://mirror.mirantis.com/proposed/saltstack-2017.7/trusty/SALTSTACK-GPG-KEY.pub"
+###
+# Hard-coded folder in template
+export PACKER_IMAGES_CACHE="${HOME}/packer_images_cache/"
+mkdir -p "${PACKER_IMAGES_CACHE}"
+
+export PACKER_LOG=1
+# For qemu test-build:
+cloud-localds  --hostname ubuntu --dsmode local config-drive/cloudata.iso  config-drive/user-data.yaml
+packer build -only=qemu -parallel=false -on-error=ask template.json
+#rm -rf ~/.packer.d/
+
diff --git a/ubuntu-14.04/scripts/base.sh b/ubuntu-14.04/scripts/base.sh
deleted file mode 100644
index 439c5a4..0000000
--- a/ubuntu-14.04/scripts/base.sh
+++ /dev/null
@@ -1,70 +0,0 @@
-## Base packages and setup
-export DEBIAN_FRONTEND=noninteractive
-echo "exit 101" > /usr/sbin/policy-rc.d
-chmod +x /usr/sbin/policy-rc.d
-
-echo "Acquire::CompressionTypes::Order gz;" >/etc/apt/apt.conf.d/99compression-workaround-salt
-
-# Overwrite default mirrors
-echo "deb mirror://mirrors.ubuntu.com/mirrors.txt trusty main restricted multiverse universe" > /etc/apt/sources.list
-echo "deb mirror://mirrors.ubuntu.com/mirrors.txt trusty-updates main restricted multiverse universe" >> /etc/apt/sources.list
-echo "deb mirror://mirrors.ubuntu.com/mirrors.txt trusty-security main restricted multiverse universe" >> /etc/apt/sources.list
-echo "deb mirror://mirrors.ubuntu.com/mirrors.txt trusty-backports main restricted multiverse universe" >> /etc/apt/sources.list
-
-# Add apt repository
-echo "deb [arch=amd64] http://apt.mirantis.com/trusty/ nightly salt" > /etc/apt/sources.list.d/mcp_salt.list
-echo "deb [arch=amd64] http://apt.mirantis.com/trusty/ nightly extra" > /etc/apt/sources.list.d/mcp_extra.list
-curl -sf http://apt.mirantis.com/public.gpg | apt-key add -
-
-apt-get clean
-apt-get update
-
-# Useful tools
-apt-get -y install byobu curl ethtool htop iputils-ping lsof strace tcpdump tmux traceroute tree vim-nox wget
-# Install common prerequisites
-apt-get -y install apt-transport-https libmnl0 python-apt python-m2crypto python-psutil
-
-# Cleanup old kernels, ensure latest is installed via virtual package
-apt-get purge -y linux-image-* linux-headers-*
-if [ ! -f /tmp/no_install_kernel ]; then
-    apt-get install -y linux-generic-lts-xenial
-
-    # Update grub cmdline
-    sed -i 's|GRUB_CMDLINE_LINUX_DEFAULT=.*|GRUB_CMDLINE_LINUX_DEFAULT="console=tty0 console=ttyS0,115200n8"|g' /etc/default/grub
-    sed -i 's|GRUB_CMDLINE_LINUX=.*|GRUB_CMDLINE_LINUX="console=tty0 console=ttyS0,115200n8"|g' /etc/default/grub
-    update-grub
-fi
-
-apt-get -y upgrade
-apt-get -y dist-upgrade
-
-apt-get autoremove --purge
-
-# Tmux fixes
-cat << 'EOF' >> /etc/tmux.conf
-set -g default-terminal "screen-256color"
-set -g set-titles on
-set -g xterm-keys on
-EOF
-
-# Install common prerequisites
-apt-get -y install apt-transport-https libmnl0 python-apt python-m2crypto python-psutil
-
-# Setup cloud-init
-apt-get -y install cloud-init
-
-# Motd
-apt-get -y install update-motd
-rm -vf /etc/update-motd.d/*
-echo "BUILD_TIMESTAMP=$(date '+%Y-%m-%d-%H-%M-%S' -u)" > /etc/image_version
-echo "BUILD_TIMESTAMP_RFC=\"$(date -u -R)\"" >> /etc/image_version
-cat << 'EOF' >> /etc/update-motd.d/00-header-mirantis
-#!/bin/sh
-#
-#    00-header - create the header of the MOTD
-#
-[ -r /etc/image_version ] && . /etc/image_version
-echo "Ubuntu 14.04 \"Trusty\" Mirantis cloud image"
-echo "Build date: ${BUILD_TIMESTAMP_RFC}"
-EOF
-chmod +x /etc/update-motd.d/00-header-mirantis
diff --git a/ubuntu-14.04/scripts/base.sh b/ubuntu-14.04/scripts/base.sh
new file mode 120000
index 0000000..7df0165
--- /dev/null
+++ b/ubuntu-14.04/scripts/base.sh
@@ -0,0 +1 @@
+../../common/ubuntu_trusty_base.sh
\ No newline at end of file
diff --git a/ubuntu-14.04/scripts/cleanup.sh b/ubuntu-14.04/scripts/cleanup.sh
deleted file mode 100644
index 7f2ba4d..0000000
--- a/ubuntu-14.04/scripts/cleanup.sh
+++ /dev/null
@@ -1,23 +0,0 @@
-apt-get -y autoremove --purge
-apt-get -y clean
-rm -f /var/lib/apt/lists/*
-
-rm -f /usr/sbin/policy-rc.d || true
-
-echo "cleaning up hostname"
-sed -i "/.*ubuntu-1404.*/d" /etc/hosts
-
-echo "cleaning up guest additions"
-rm -rf VBoxGuestAdditions_*.iso VBoxGuestAdditions_*.iso.? || true
-
-echo "cleaning up dhcp leases"
-rm -f /var/lib/dhcp/* || true
-
-echo "cleaning up udev rules"
-rm -f /etc/udev/rules.d/70-persistent-net.rules || true
-rm -rf /dev/.udev/ || true
-rm -f /lib/udev/rules.d/75-persistent-net-generator.rules || true
-
-echo "cleaning up minion_id for salt"
-rm -f /etc/salt/minion_id || true
-
diff --git a/ubuntu-14.04/scripts/cleanup.sh b/ubuntu-14.04/scripts/cleanup.sh
new file mode 120000
index 0000000..cf970b6
--- /dev/null
+++ b/ubuntu-14.04/scripts/cleanup.sh
@@ -0,0 +1 @@
+../../common/ubuntu_cleanup.sh
\ No newline at end of file
diff --git a/ubuntu-14.04/scripts/docker.sh b/ubuntu-14.04/scripts/docker.sh
index 9ae4add..bd79ed8 100644
--- a/ubuntu-14.04/scripts/docker.sh
+++ b/ubuntu-14.04/scripts/docker.sh
@@ -1,5 +1,6 @@
 # This should simulate preseed behavior
 
+apt-get update
 apt-get -y install curl
 
 # Add apt repository
@@ -7,6 +8,7 @@
 echo "deb [arch=amd64] http://apt.mirantis.com/trusty/ nightly extra" > /etc/apt/sources.list.d/mcp_extra.list
 curl -sf http://apt.mirantis.com/public.gpg | apt-key add -
 
+apt-get clean
 apt-get update
 
 # Kernel makes no sense in docker, let base.sh know
diff --git a/ubuntu-14.04/scripts/info.sh b/ubuntu-14.04/scripts/info.sh
new file mode 120000
index 0000000..772d054
--- /dev/null
+++ b/ubuntu-14.04/scripts/info.sh
@@ -0,0 +1 @@
+../../common/ubuntu_info.sh
\ No newline at end of file
diff --git a/ubuntu-14.04/scripts/motd.sh b/ubuntu-14.04/scripts/motd.sh
new file mode 100644
index 0000000..e215a29
--- /dev/null
+++ b/ubuntu-14.04/scripts/motd.sh
@@ -0,0 +1,17 @@
+#!/bin/bash -xe
+# Motd
+apt-get -y install update-motd
+rm -vf /etc/update-motd.d/*
+echo "BUILD_TIMESTAMP=$(date '+%Y-%m-%d-%H-%M-%S' -u)" > /etc/image_version
+echo "BUILD_TIMESTAMP_RFC=\"$(date -u -R)\"" >> /etc/image_version
+cat << 'EOF' >> /etc/update-motd.d/00-header-mirantis
+#!/bin/sh
+#
+#    00-header - create the header of the MOTD
+#
+[ -r /etc/image_version ] && . /etc/image_version
+echo "Ubuntu 16.04 \"Trusty\" Mirantis cloud image"
+echo "Build date: ${BUILD_TIMESTAMP_RFC}"
+EOF
+chmod +x /etc/update-motd.d/00-header-mirantis
+
diff --git a/ubuntu-14.04/scripts/network.sh b/ubuntu-14.04/scripts/network.sh
new file mode 120000
index 0000000..ab1de37
--- /dev/null
+++ b/ubuntu-14.04/scripts/network.sh
@@ -0,0 +1 @@
+../../common/ubuntu_network.sh
\ No newline at end of file
diff --git a/ubuntu-14.04/scripts/salt.sh b/ubuntu-14.04/scripts/salt.sh
index b5d5813..4228bb8 100644
--- a/ubuntu-14.04/scripts/salt.sh
+++ b/ubuntu-14.04/scripts/salt.sh
@@ -1,9 +1,19 @@
-wget -O - https://repo.saltstack.com/apt/ubuntu/14.04/amd64/2016.3/SALTSTACK-GPG-KEY.pub | sudo apt-key add -
-echo "deb http://repo.saltstack.com/apt/ubuntu/14.04/amd64/2016.3 trusty main" >/etc/apt/sources.list.d/saltstack.list
+#!/bin/bash -xe
+
+SALTSTACK_REPO=${SALTSTACK_REPO:-"deb [arch=amd64] https://mirror.mirantis.com/stable/saltstack-2017.7/trusty/ trusty main"}
+SALTSTACK_GPG=${SALTSTACK_GPG:-"https://repo.saltstack.com/apt/ubuntu/16.04/amd64/2016.3/SALTSTACK-GPG-KEY.pub"}
+
+wget -O - ${SALTSTACK_GPG} | sudo apt-key add -
+echo "${SALTSTACK_REPO}" > /etc/apt/sources.list.d/saltstack.list
+
+# We expect issues with GPG,related to our mirrors - so temporary disable check.
+echo "APT::Get::AllowUnauthenticated true;" > /etc/apt/apt.conf.d/99allow_unauthenticated
+
 apt-get update
 apt-get -y install salt-minion
 mkdir -m700 -p /etc/salt/pki/minion
-echo "
+
+cat <<EOF >> /etc/salt/minion.d/minion.conf
 max_event_size: 100000000
 acceptance_wait_time_max: 60
 acceptance_wait_time: 10
@@ -11,4 +21,8 @@
 recon_default: 1000
 recon_max: 60000
 recon_randomize: True
-auth_timeout: 60" >> /etc/salt/minion
+auth_timeout: 60
+EOF
+
+rm -vf /etc/apt/apt.conf.d/99allow_unauthenticated
+rm -vf /etc/apt/sources.list.d/saltstack.list
diff --git a/ubuntu-14.04/scripts/security.sh b/ubuntu-14.04/scripts/security.sh
new file mode 120000
index 0000000..31e630f
--- /dev/null
+++ b/ubuntu-14.04/scripts/security.sh
@@ -0,0 +1 @@
+../../common/ubuntu_trusty_security.sh
\ No newline at end of file
diff --git a/ubuntu-14.04/template.json b/ubuntu-14.04/template.json
index b91fa95..76d1309 100644
--- a/ubuntu-14.04/template.json
+++ b/ubuntu-14.04/template.json
@@ -1,21 +1,41 @@
 {
   "variables": {
     "user": "root",
-    "password": "ho5uo7Uome5d",
-    "do_api_token": "{{ env `DO_API_TOKEN` }}",
+    "password": "r00tme",
     "distro": "ubuntu-14-04-x64",
+    "disk_size": "8000",
+    "images_cache": "{{ env `PACKER_IMAGES_CACHE` }}",
+    "ubuntu_baseurl": "https://mirror.mirantis.com/proposed/ubuntu/",
+    "saltstack_gpg": "{{ env `SALTSTACK_GPG` }}",
+    "saltstack_repo": "{{ env `SALTSTACK_REPO` }}",
+    "do_api_token": "{{ env `DO_API_TOKEN` }}",
     "image_name": "{{ env `IMAGE_NAME` }}",
-    "disk_size": "8000"
+    "os_username": "{{ env `OS_USERNAME` }}",
+    "os_password": "{{ env `OS_PASSWORD` }}",
+    "os_image": "7451fac0-0ce5-4d30-ae36-cd9a90e7948e",
+    "os_endpoint": "https://cloud-cz.bud.mirantis.net:5000/v2.0",
+    "os_zone": "mcp-mk",
+    "os_floating_ip_pool": "public",
+    "os_tenant": "26e4dd19485249608ee3685f254f3909",
+    "os_network": "772f8ca6-1f4a-4535-99d0-880d6ead9a82"
   },
   "provisioners": [
     {
       "type": "shell",
-      "execute_command": "sh '{{.Path}}'",
+      "execute_command": "chmod +x {{ .Path }}; {{ .Vars }} {{ .Path }}",
+      "expect_disconnect": "true",
+      "environment_vars": [
+        "UBUNTU_BASEURL={{ user `ubuntu_baseurl` }}",
+        "SALTSTACK_GPG={{ user `saltstack_gpg` }}",
+        "SALTSTACK_REPO={{ user `saltstack_repo` }}"
+      ],
       "override": {
         "virtualbox-iso": {
           "scripts": [
             "scripts/base.sh",
+            "scripts/motd.sh",
             "scripts/salt.sh",
+            "scripts/network.sh",
             "scripts/vagrant.sh",
             "scripts/virtualbox.sh",
             "scripts/security.sh",
@@ -26,6 +46,7 @@
         "vmware-iso": {
           "scripts": [
             "scripts/base.sh",
+            "scripts/motd.sh",
             "scripts/salt.sh",
             "scripts/vmware.sh",
             "scripts/security.sh",
@@ -36,9 +57,24 @@
         "qemu": {
           "scripts": [
             "scripts/base.sh",
+            "scripts/motd.sh",
             "scripts/salt.sh",
+            "scripts/network.sh",
             "scripts/security.sh",
             "scripts/cleanup.sh",
+            "scripts/info.sh",
+            "scripts/zerodisk.sh"
+          ]
+        },
+        "openstack": {
+          "scripts": [
+            "scripts/base.sh",
+            "scripts/motd.sh",
+            "scripts/salt.sh",
+            "scripts/network.sh",
+            "scripts/security.sh",
+            "scripts/cleanup.sh",
+            "scripts/info.sh",
             "scripts/zerodisk.sh"
           ]
         },
@@ -46,6 +82,7 @@
           "scripts": [
             "scripts/docker.sh",
             "scripts/base.sh",
+            "scripts/motd.sh",
             "scripts/salt.sh",
             "scripts/cleanup.sh"
           ]
@@ -53,6 +90,7 @@
         "digitalocean": {
           "scripts": [
             "scripts/base.sh",
+            "scripts/motd.sh",
             "scripts/salt.sh",
             "scripts/security.sh",
             "scripts/cleanup.sh"
@@ -62,12 +100,12 @@
     },
     {
       "type": "file",
-      "source": "configs/cloud/cloud.cfg.d/99_tcp.cfg",
+      "source": "files/etc/cloud/cloud.cfg.d/99_tcp.cfg",
       "destination": "/etc/cloud/cloud.cfg.d/99_tcp.cfg"
     },
     {
       "type": "file",
-      "source": "configs/cloud/cloud.cfg",
+      "source": "files/etc/cloud/cloud.cfg",
       "destination": "/etc/cloud/cloud.cfg"
     }
   ],
@@ -131,14 +169,14 @@
       "output_directory": "images/{{ user `distro` }}-vbox-{{ isotime \"200601021504\"  }}",
       "guest_os_type": "Ubuntu_64",
       "http_directory": "http",
-      "iso_checksum": "dd54dc8cfc2a655053d19813c2f9aa9f",
+      "iso_checksum": "10fcd20619dce11fe094e960c85ba4a9",
       "iso_checksum_type": "md5",
-      "iso_url": "http://releases.ubuntu.mirror.dkm.cz/releases/14.04/ubuntu-14.04.5-server-amd64.iso",
+      "iso_url": "http://releases.ubuntu.com/14.04/ubuntu-14.04.3-server-amd64.iso",
       "ssh_username": "{{user `user`}}",
       "ssh_password": "{{user `password`}}",
       "ssh_port": 22,
       "ssh_wait_timeout": "10000s",
-      "shutdown_command": "shutdown -P now",
+      "shutdown_command": "pgrep -f 'sshd: root@' | xargs kill -9 ; shutdown -P now",
       "headless": true,
       "vboxmanage": [
         [
@@ -208,14 +246,14 @@
       "output_directory": "images/{{ user `distro` }}-vmware-{{ isotime \"200601021504\"  }}",
       "guest_os_type": "linux",
       "http_directory": "http",
-      "iso_checksum": "dd54dc8cfc2a655053d19813c2f9aa9f",
+      "iso_checksum": "10fcd20619dce11fe094e960c85ba4a9",
       "iso_checksum_type": "md5",
-      "iso_url": "http://releases.ubuntu.mirror.dkm.cz/releases/14.04/ubuntu-14.04.5-server-amd64.iso",
+      "iso_url": "http://releases.ubuntu.com/14.04/ubuntu-14.04.3-server-amd64.iso",
       "ssh_username": "{{user `user`}}",
       "ssh_password": "{{user `password`}}",
       "ssh_port": 22,
       "ssh_wait_timeout": "10000s",
-      "shutdown_command": "shutdown -P now",
+      "shutdown_command": "pgrep -f 'sshd: root@' | xargs kill -9 ; shutdown -P now",
       "vmx_data": {
         "memsize": "1024",
         "numvcpus": "1",
@@ -223,56 +261,6 @@
       }
     },
     {
-      "type": "qemu",
-      "qemuargs": [
-        [
-          "-m",
-          "1024M"
-        ]
-      ],
-      "vm_name": "{{ user `image_name` }}-{{ isotime \"200601021504\"  }}",
-      "output_directory": "images/{{ user `distro` }}-qemu-{{ isotime \"200601021504\"  }}",
-      "format": "qcow2",
-      "accelerator": "kvm",
-      "disk_size": "{{ user `disk_size`}}",
-      "iso_url": "http://releases.ubuntu.mirror.dkm.cz/releases/14.04/ubuntu-14.04.5-server-amd64.iso",
-      "iso_checksum_type": "md5",
-      "iso_checksum": "dd54dc8cfc2a655053d19813c2f9aa9f",
-      "http_directory": "http",
-      "headless": true,
-      "ssh_username": "{{user `user`}}",
-      "ssh_password": "{{user `password`}}",
-      "shutdown_command": "shutdown -P now",
-      "boot_wait": "2s",
-      "ssh_wait_timeout": "10000s",
-      "boot_command": [
-        "<esc><wait>",
-        "<esc><wait>",
-        "<enter><wait>",
-        "/install/vmlinuz<wait>",
-        " auto<wait>",
-        " console-setup/ask_detect=false<wait>",
-        " console-setup/layoutcode=us<wait>",
-        " console-setup/modelcode=pc105<wait>",
-        " debconf/frontend=noninteractive<wait>",
-        " debian-installer=en_US<wait>",
-        " fb=false<wait>",
-        " initrd=/install/initrd.gz<wait>",
-        " kbd-chooser/method=us<wait>",
-        " keyboard-configuration/layout=USA<wait>",
-        " keyboard-configuration/variant=USA<wait>",
-        " passwd/root-password={{user `password`}} ",
-        " passwd/root-password-again={{user `password`}} ",
-        " locale=en_US<wait>",
-        " netcfg/get_hostname=ubuntu-1404<wait>",
-        " netcfg/get_domain=changeme<wait>",
-        " noapic<wait>",
-        " preseed/url=http://{{ .HTTPIP }}:{{ .HTTPPort }}/preseed.cfg<wait>",
-        " -- <wait>",
-        "<enter><wait>"
-      ]
-    },
-    {
       "type": "docker",
       "image": "ubuntu:14.04",
       "commit": true
@@ -284,6 +272,49 @@
       "snapshot_name": "{{ user `image_name` }}-{{ isotime \"200601021504\"  }}",
       "region": "ams2",
       "size": "1gb"
+    },
+    {
+      "type": "qemu",
+      "qemuargs": [
+        [ "-m", "1024M" ],
+        [ "-cdrom", "config-drive/cloudata.iso" ]
+      ],
+      "vm_name": "{{ user `image_name` }}-{{ isotime \"200601021504\"  }}",
+      "output_directory": "images/{{ user `image_name` }}-qemu-{{ isotime \"200601021504\"  }}",
+      "format": "qcow2",
+      "iso_checksum": "06d561ab1ae8723493b484c1effc2790",
+      "iso_checksum_type": "md5",
+      "iso_url": "http://cloud-images.ubuntu.com/releases/trusty/release-20180703/ubuntu-14.04-server-cloudimg-amd64-disk1.img",
+      "iso_target_path": "{{ user `images_cache`}}/release-20180703_ubuntu-14.04-server-cloudimg-amd64-disk1.img",
+      "disk_image": true,
+      "disk_compression": true,
+      "accelerator": "kvm",
+      "disk_size": "{{ user `disk_size`}}",
+      "headless": true,
+      "ssh_username": "{{ user `user` }}",
+      "ssh_password": "{{ user `password` }}",
+      "ssh_host_port_min": 7000,
+      "ssh_host_port_max": 7050,
+      "shutdown_command": "pgrep -f 'sshd: root@' | xargs kill -9 ; shutdown -P now",
+      "boot_wait": "2s",
+      "ssh_wait_timeout": "360s"
+    },
+    {
+      "type": "openstack",
+      "ssh_username": "{{ user `user` }}",
+      "ssh_password": "{{ user `password` }}",
+      "image_name": "{{user `image_name`}}",
+      "floating_ip_pool": "{{user `os_floating_ip_pool`}}",
+      "reuse_ips": "true",
+      "source_image": "{{ user `os_image` }}",
+      "flavor": "{{ user `os_flavor` }}",
+      "user_data_file": "config-drive/user-data.yaml",
+      "tenant_id": "{{ user `os_tenant` }}",
+      "networks": ["{{ user `os_network` }}"],
+      "availability_zone": "{{user `os_zone`}}",
+      "identity_endpoint": "{{user `os_endpoint`}}",
+      "username": "{{user `os_username`}}",
+      "password": "{{user `os_password`}}"
     }
   ]
-}
\ No newline at end of file
+}
diff --git a/ubuntu-14.04/template.json.env b/ubuntu-14.04/template.json.env
new file mode 100644
index 0000000..6eb61c4
--- /dev/null
+++ b/ubuntu-14.04/template.json.env
@@ -0,0 +1,17 @@
+# Env variables and description:
+#DO_API_TOKEN
+PACKER_IMAGES_CACHE="${HOME}/packer_images_cache/"
+
+
+# base.sh
+UBUNTU_BASEURL=http://mirror.mirantis.com/stable/ubuntu/
+
+# salt.sh
+SALTSTACK_REPO=${SALTSTACK_REPO:-"deb [arch=amd64] https://mirror.mirantis.com/stable/saltstack-2016.3/trusty/ trusty main"}
+SALTSTACK_GPG=${SALTSTACK_GPG:-"https://repo.saltstack.com/apt/ubuntu/16.04/amd64/2016.3/SALTSTACK-GPG-KEY.pub"}
+
+
+
+# resulted openstack|qemu image name part
+IMAGE_NAME="ubuntu-14-04-x64"
+
diff --git a/ubuntu-16.04/template.json b/ubuntu-16.04/template.json
index e36e506..40d49e0 100644
--- a/ubuntu-16.04/template.json
+++ b/ubuntu-16.04/template.json
@@ -154,8 +154,8 @@
         " kbd-chooser/method=us<wait>",
         " keyboard-configuration/layout=USA<wait>",
         " keyboard-configuration/variant=USA<wait>",
-        " passwd/root-password={{user `password`}} ",
-        " passwd/root-password-again={{user `password`}} ",
+        " passwd/root-password={{ user `password` }} ",
+        " passwd/root-password-again={{ user `password` }} ",
         " locale=en_US<wait>",
         " netcfg/get_hostname=ubuntu-1604<wait>",
         " netcfg/get_domain=cloudlab.cz<wait>",
@@ -172,8 +172,8 @@
       "iso_checksum": "10fcd20619dce11fe094e960c85ba4a9",
       "iso_checksum_type": "md5",
       "iso_url": "http://releases.ubuntu.com/16.04/ubuntu-16.04.3-server-amd64.iso",
-      "ssh_username": "{{user `user`}}",
-      "ssh_password": "{{user `password`}}",
+      "ssh_username": "{{ user `user` }}",
+      "ssh_password": "{{ user `password` }}",
       "ssh_port": 22,
       "ssh_wait_timeout": "10000s",
       "shutdown_command": "pgrep -f 'sshd: root@' | xargs kill -9 ; shutdown -P now",
@@ -277,7 +277,7 @@
       "type": "qemu",
       "qemuargs": [
         [ "-m", "1024M" ],
-        [ "-fda", "config-drive/cloudata.iso" ]
+        [ "-cdrom", "config-drive/cloudata.iso" ]
       ],
       "vm_name": "{{ user `image_name` }}-{{ isotime \"200601021504\"  }}",
       "output_directory": "images/{{ user `image_name` }}-qemu-{{ isotime \"200601021504\"  }}",
@@ -291,8 +291,8 @@
       "accelerator": "kvm",
       "disk_size": "{{ user `disk_size`}}",
       "headless": true,
-      "ssh_username": "{{user `user`}}",
-      "ssh_password": "{{user `password`}}",
+      "ssh_username": "{{ user `user` }}",
+      "ssh_password": "{{ user `password` }}",
       "ssh_host_port_min": 7000,
       "ssh_host_port_max": 7050,
       "shutdown_command": "pgrep -f 'sshd: root@' | xargs kill -9 ; shutdown -P now",