From a2198ae35b2ed0332580f11829a860ce9d31100d Mon Sep 17 00:00:00 2001 From: Tollef Fog Heen Date: Mon, 7 Apr 2014 10:53:52 +0200 Subject: [PATCH] Ignore failure to set host name At least minbase does not end up with an /etc/hosts file, so ignore IOErrors for the hosts file. --- vmdebootstrap | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/vmdebootstrap b/vmdebootstrap index 3344a59..a9f9e9b 100755 --- a/vmdebootstrap +++ b/vmdebootstrap @@ -292,13 +292,16 @@ class VmDebootstrap(cliapp.Application): 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) + try: + 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) + except IOError, e: + pass def create_fstab(self, rootdir, rootdev, roottype, bootdev, boottype): def fsuuid(device): -- 2.39.5