summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2011-06-29 16:24:33 +0100
committerLars Wirzenius <liw@liw.fi>2011-06-29 16:24:33 +0100
commit6906af4d702987376af64b4229763672f7c1eca2 (patch)
tree01bd148a99e7507d2cd7f0807cd44e4484fc2595
parenta7031c97fddc7db735b930677551343efa5e2249 (diff)
downloadvmdebootstrap-6906af4d702987376af64b4229763672f7c1eca2.tar.gz
Add hostname to /etc/hosts.
-rwxr-xr-xvmdebootstrap9
1 files changed, 9 insertions, 0 deletions
diff --git a/vmdebootstrap b/vmdebootstrap
index 2fc5590..61f0760 100755
--- a/vmdebootstrap
+++ b/vmdebootstrap
@@ -174,6 +174,15 @@ class VmDebootstrap(cliapp.Application):
hostname = self.settings['hostname']
with open(os.path.join(rootdir, 'etc', 'hostname'), 'w') as f:
f.write('%s\n' % hostname)
+
+ etc_hosts = os.path.join(rootdir, 'etc', 'hosts')
+ with open(etc_hosts, 'r') as f:
+ data = f.read()
+ with open(etc_hosts, 'w') as f:
+ for line in data.splitlines():
+ if line.startswith('127.0.0.1'):
+ line += ' %s' % hostname
+ f.write('%s\n' % line)
def set_root_password(self, rootdir):
if self.settings['root-password']: