From 3b80ba32c71d071140dc702f9a3a835114f3cd6f Mon Sep 17 00:00:00 2001
From: John Van de Meulebrouck Brendgard <john@sunet.se>
Date: Wed, 13 Feb 2019 19:07:04 +0100
Subject: [PATCH] Set manage_etc_hosts to false for cloudimage based hosts

this is needed so that our changes in /etc/hosts
are not overwritten.
---
 global/overlay/etc/cosmos/apt/bootstrap-cosmos.sh | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/global/overlay/etc/cosmos/apt/bootstrap-cosmos.sh b/global/overlay/etc/cosmos/apt/bootstrap-cosmos.sh
index a93de05..c1ccf8c 100755
--- a/global/overlay/etc/cosmos/apt/bootstrap-cosmos.sh
+++ b/global/overlay/etc/cosmos/apt/bootstrap-cosmos.sh
@@ -51,6 +51,12 @@ mv -f /etc/rc.local.new /etc/rc.local
 
 touch /etc/run-cosmos-at-boot
 
+# If this cloud-config is set, it will interfere with our changes to /etc/hosts
+grep -q 'manage_etc_hosts: true' /etc/cloud/cloud.cfg
+if [ ${?} -eq 0 ]; then
+    sed -i 's/manage_etc_hosts: true/manage_etc_hosts: false/g' /etc/cloud/cloud.cfg
+fi
+
 hostname $cmd_hostname
 short=`echo ${cmd_hostname} | awk -F. '{print $1}'`
 echo "127.0.1.1 ${cmd_hostname} ${short}" >> /etc/hosts