From dcae0e156e98e8a06ea08b6443e87156a9b24e73 Mon Sep 17 00:00:00 2001 From: Anders Ingemann Date: Sun, 12 Jan 2014 12:44:32 +0100 Subject: [PATCH] Vagrant plugin creates its own user etc. now There is no need to rely on other plugins any longer --- manifests/virtualbox-vagrant.manifest.json | 9 +---- plugins/vagrant/__init__.py | 3 ++ plugins/vagrant/manifest-schema.json | 18 +--------- plugins/vagrant/tasks.py | 42 ++++++++++++++++++++-- 4 files changed, 45 insertions(+), 27 deletions(-) diff --git a/manifests/virtualbox-vagrant.manifest.json b/manifests/virtualbox-vagrant.manifest.json index 07a2c7e..7a07431 100644 --- a/manifests/virtualbox-vagrant.manifest.json +++ b/manifests/virtualbox-vagrant.manifest.json @@ -33,13 +33,6 @@ } }, "plugins": { - "admin_user": { - "username": "vagrant" - }, - "root_password": { - "password": "vagrant" - }, - "vagrant": { - } + "vagrant": {} } } diff --git a/plugins/vagrant/__init__.py b/plugins/vagrant/__init__.py index 2bb2376..8d44c58 100644 --- a/plugins/vagrant/__init__.py +++ b/plugins/vagrant/__init__.py @@ -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, diff --git a/plugins/vagrant/manifest-schema.json b/plugins/vagrant/manifest-schema.json index f432bd2..c6720d7 100644 --- a/plugins/vagrant/manifest-schema.json +++ b/plugins/vagrant/manifest-schema.json @@ -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"] + } } diff --git a/plugins/vagrant/tasks.py b/plugins/vagrant/tasks.py index f4cf2ae..aceef15 100644 --- a/plugins/vagrant/tasks.py +++ b/plugins/vagrant/tasks.py @@ -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