From e9d544cc0b5a29066db7bec5462c71f29858f841 Mon Sep 17 00:00:00 2001 From: Roger Luethi <rl@patchworkscience.org> Date: Wed, 18 Jun 2014 09:05:27 +0200 Subject: [PATCH] Edit /etc/hosts This script makes sure the hostname can be resolved through /etc/hosts and adds names for all interfaces in the VM cluster. Partial-Bug: 1312764 Implements: blueprint openstack-training-labs Change-Id: Id35a9d698bf981ff960e7898b8bcb0a598b1b58c --- labs/scripts/etc_hosts.sh | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 labs/scripts/etc_hosts.sh diff --git a/labs/scripts/etc_hosts.sh b/labs/scripts/etc_hosts.sh new file mode 100644 index 00000000..13402f0c --- /dev/null +++ b/labs/scripts/etc_hosts.sh @@ -0,0 +1,25 @@ +#!/usr/bin/env bash +TOP_DIR=$(cd $(dirname "$0")/.. && pwd) +source "$TOP_DIR/config/paths" +source "$LIB_DIR/functions.guest" + +indicate_current_auto + +exec_logfile + +HOST_NAME=$(hostname) +HOST_FILE=/etc/hosts + +if ! grep -q "^[^#].*$HOST_NAME" $HOST_FILE; then + # No active entry for our hostname + HOST_IP=127.0.1.1 + if grep -q "^$HOST_IP" $HOST_FILE; then + # Fix the entry for the IP address we want to use + sudo sed -i "s/^$HOST_IP.*/$HOST_IP $HOST_NAME/" $HOST_FILE + else + echo "$HOST_IP $HOST_NAME" | sudo tee -a $HOST_FILE + fi +fi + +# Add entries for the rest of the OpenStack training-labs +cat "$CONFIG_DIR/hosts.multi" | sudo tee -a /etc/hosts