mirror of
https://github.com/kevingruesser/bootstrap-vz.git
synced 2025-10-07 17:40:30 +00:00
Set the hostname on vagrant boxes
This commit is contained in:
parent
81dab9c147
commit
8902e5d93f
3 changed files with 34 additions and 0 deletions
|
@ -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,
|
||||
|
|
|
@ -18,6 +18,21 @@
|
|||
}
|
||||
},
|
||||
"required": ["backing"]
|
||||
},
|
||||
"plugins": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"vagrant": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"hostname": {
|
||||
"type": "string",
|
||||
"pattern": "^\\S+$"
|
||||
}
|
||||
},
|
||||
"required": ["hostname"]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Add table
Reference in a new issue