Vagrant plugin creates its own user etc. now

There is no need to rely on other plugins any longer
This commit is contained in:
Anders Ingemann 2014-01-12 12:44:32 +01:00
parent e340a96db3
commit dcae0e156e
4 changed files with 45 additions and 27 deletions

View file

@ -33,13 +33,6 @@
}
},
"plugins": {
"admin_user": {
"username": "vagrant"
},
"root_password": {
"password": "vagrant"
},
"vagrant": {
}
"vagrant": {}
}
}

View file

@ -16,6 +16,9 @@ def resolve_tasks(taskset, manifest):
from common.tasks import volume
taskset.update([tasks.CreateVagrantBoxDir,
tasks.AddPackages,
tasks.CreateVagrantUser,
tasks.PasswordlessSudo,
tasks.SetRootPassword,
tasks.AddInsecurePublicKey,
tasks.PackageBox,
tasks.RemoveVagrantBoxDir,

View file

@ -18,22 +18,6 @@
}
},
"required": ["backing"]
},
"plugins": {
"type": "object",
"properties": {
"root_password": {
"type": "object",
"properties": {
"password": {
"type": "string"
}
},
"required": ["password"]
}
},
"required": ["root_password"]
}
},
"required": ["plugins"]
}
}

View file

@ -2,7 +2,6 @@ from base import Task
from common import phases
from common.tasks import workspace
from common.tasks import apt
from plugins.admin_user.tasks import CreateAdminUser
import os
import shutil
@ -28,12 +27,41 @@ class AddPackages(Task):
@classmethod
def run(cls, info):
info.packages.add('openssh-server')
info.packages.add('sudo')
info.packages.add('nfs-client')
class CreateVagrantUser(Task):
description = 'Creating the vagrant user'
phase = phases.system_modification
@classmethod
def run(cls, info):
from common.tools import log_check_call
log_check_call(['/usr/sbin/chroot', info.root,
'/usr/sbin/useradd',
'--create-home', '--shell', '/bin/bash',
'vagrant'])
class PasswordlessSudo(Task):
description = 'Allowing the vagrant user to use sudo without a password'
phase = phases.system_modification
@classmethod
def run(cls, info):
sudo_vagrant_path = os.path.join(info.root, 'etc/sudoers.d/vagrant')
with open(sudo_vagrant_path, 'w') as sudo_vagrant:
sudo_vagrant.write('vagrant ALL=(ALL) NOPASSWD:ALL')
import stat
ug_read_only = (stat.S_IRUSR | stat.S_IRGRP)
os.chmod(sudo_vagrant_path, ug_read_only)
class AddInsecurePublicKey(Task):
description = 'Adding vagrant insecure public key'
phase = phases.system_modification
predecessors = [CreateAdminUser]
predecessors = [CreateVagrantUser]
@classmethod
def run(cls, info):
@ -49,6 +77,16 @@ class AddInsecurePublicKey(Task):
authorized_keys.write(insecure_public_key)
class SetRootPassword(Task):
description = 'Setting the root password to `vagrant\''
phase = phases.system_modification
@classmethod
def run(cls, info):
from common.tools import log_check_call
log_check_call(['/usr/sbin/chroot', info.root, '/usr/sbin/chpasswd'], 'root:vagrant')
class PackageBox(Task):
description = 'Packaging the volume as a vagrant box'
phase = phases.image_registration