Set the hostname on vagrant boxes

This commit is contained in:
Anders Ingemann 2014-01-20 21:21:09 +01:00
parent 81dab9c147
commit 8902e5d93f
3 changed files with 34 additions and 0 deletions

View file

@ -10,13 +10,16 @@ def validate_manifest(data, validator, error):
def resolve_tasks(taskset, manifest):
from common.tasks import security
from common.tasks import loopback
from common.tasks import network
taskset.discard(security.DisableSSHPasswordAuthentication)
taskset.discard(loopback.MoveImage)
taskset.discard(network.RemoveHostname)
from common.tasks import volume
taskset.update([tasks.CheckBoxPath,
tasks.CreateVagrantBoxDir,
tasks.AddPackages,
tasks.SetHostname,
tasks.CreateVagrantUser,
tasks.PasswordlessSudo,
tasks.SetRootPassword,

View file

@ -18,6 +18,21 @@
}
},
"required": ["backing"]
},
"plugins": {
"type": "object",
"properties": {
"vagrant": {
"type": "object",
"properties": {
"hostname": {
"type": "string",
"pattern": "^\\S+$"
}
},
"required": ["hostname"]
}
}
}
}
}

View file

@ -48,6 +48,22 @@ class AddPackages(Task):
info.packages.add('nfs-client')
class SetHostname(Task):
description = 'Writing hostname into the hostname file'
phase = phases.system_modification
@classmethod
def run(cls, info):
hostname = info.manifest.plugins['vagrant']['hostname'].format(**info.manifest_vars)
hostname_file_path = os.path.join(info.root, 'etc/hostname')
with open(hostname_file_path, 'w') as hostname_file:
hostname_file.write(hostname)
hosts_path = os.path.join(info.root, 'etc/hosts')
from common.tools import sed_i
sed_i(hosts_path, '^127.0.0.1\tlocalhost$', '127.0.0.1\tlocalhost\n127.0.0.1\t' + hostname)
class CreateVagrantUser(Task):
description = 'Creating the vagrant user'
phase = phases.system_modification