diff --git a/manifests/ec2-ebs-debian-official-i386-pvm.manifest.json b/manifests/ec2-ebs-debian-official-i386-pvm.manifest.json index 9226074..a3836ea 100644 --- a/manifests/ec2-ebs-debian-official-i386-pvm.manifest.json +++ b/manifests/ec2-ebs-debian-official-i386-pvm.manifest.json @@ -43,10 +43,8 @@ { "name": "cloud-init", "target": "{release}-backports" } ] }, - "sed": { - "file": "etc/cloud/cloud.cfg", - "find": "^ name: debian$", - "replace": " name: admin\n sudo: ALL=(ALL) NOPASSWD:ALL\n shell: /bin/bash" + "cloud_init": { + "username": "admin" } } } diff --git a/manifests/ec2-ebs-debian-official.manifest.json b/manifests/ec2-ebs-debian-official.manifest.json index 78515b6..14cd563 100644 --- a/manifests/ec2-ebs-debian-official.manifest.json +++ b/manifests/ec2-ebs-debian-official.manifest.json @@ -43,10 +43,8 @@ { "name": "cloud-init", "target": "{release}-backports" } ] }, - "sed": { - "file": "etc/cloud/cloud.cfg", - "find": "^ name: debian$", - "replace": " name: admin\n sudo: ALL=(ALL) NOPASSWD:ALL\n shell: /bin/bash" + "cloud_init": { + "username": "admin" } } } diff --git a/manifests/ec2-ebs.manifest.json b/manifests/ec2-ebs-single.manifest.json similarity index 100% rename from manifests/ec2-ebs.manifest.json rename to manifests/ec2-ebs-single.manifest.json diff --git a/plugins/cloud_init/__init__.py b/plugins/cloud_init/__init__.py new file mode 100644 index 0000000..c058ec7 --- /dev/null +++ b/plugins/cloud_init/__init__.py @@ -0,0 +1,31 @@ + + +def validate_manifest(data, schema_validate): + from os import path + schema_path = path.normpath(path.join(path.dirname(__file__), 'manifest-schema.json')) + schema_validate(data, schema_path) + packages = data['plugins']['packages'] + cloud_init_installed = False + if 'remote' in packages: + for package in packages['remote']: + if isinstance(package, basestring): + name = package + else: + name = package['name'] + if name == 'cloud-init': + cloud_init_installed = True + break + if not cloud_init_installed: + from common.exceptions import ManifestError + raise ManifestError('The cloud-init package must be installed for the cloud_init plugin to work') + + +def tasks(tasklist, manifest): + from tasks import SetUsername + from providers.ec2.tasks.initd import AddEC2InitScripts + from common.tasks import initd + tasklist.add(SetUsername) + tasklist.remove(AddEC2InitScripts, + initd.AddExpandRoot, + initd.AdjustExpandRootScript, + initd.AddSSHKeyGeneration) diff --git a/plugins/cloud_init/manifest-schema.json b/plugins/cloud_init/manifest-schema.json new file mode 100644 index 0000000..599855c --- /dev/null +++ b/plugins/cloud_init/manifest-schema.json @@ -0,0 +1,23 @@ +{ + "$schema": "http://json-schema.org/draft-04/schema#", + "title": "cloud-init plugin manifest", + "type": "object", + "properties": { + "plugins": { + "type": "object", + "properties": { + "cloud_init": { + "type": "object", + "properties": { + "username": { + "type": "string" + } + }, + "required": ["username"] + }, + "packages": {"type": "object"} + }, + "required": ["cloud_init", "packages"] + } + } +} diff --git a/plugins/cloud_init/tasks.py b/plugins/cloud_init/tasks.py new file mode 100644 index 0000000..37883f2 --- /dev/null +++ b/plugins/cloud_init/tasks.py @@ -0,0 +1,20 @@ +from base import Task +from common import phases +from plugins.packages.tasks import InstallRemotePackages + + +class SetUsername(Task): + description = 'Setting username in cloud.cfg' + phase = phases.system_modification + predecessors = [InstallRemotePackages] + + def run(self, info): + from common.tools import sed_i + import os.path + cloud_cfg = os.path.join(info.root, 'etc/cloud/cloud.cfg') + username = info.manifest.plugins['cloud_init']['username'] + search = '^ name: debian$' + replace = (' name: {username}\n' + ' sudo: ALL=(ALL) NOPASSWD:ALL\n' + ' shell: /bin/bash').format(username=username) + sed_i(cloud_cfg, search, replace) diff --git a/plugins/sed/__init__.py b/plugins/sed/__init__.py deleted file mode 100644 index c754084..0000000 --- a/plugins/sed/__init__.py +++ /dev/null @@ -1,10 +0,0 @@ - - -def tasks(tasklist, manifest): - import tasks - tasklist.add(tasks.DoSeds) - -def validate_manifest(data, schema_validate): - from os import path - schema_path = path.normpath(path.join(path.dirname(__file__), 'manifest-schema.json')) - schema_validate(data, schema_path) diff --git a/plugins/sed/manifest-schema.json b/plugins/sed/manifest-schema.json deleted file mode 100644 index df71755..0000000 --- a/plugins/sed/manifest-schema.json +++ /dev/null @@ -1,28 +0,0 @@ -{ - "$schema": "http://json-schema.org/draft-04/schema#", - "title": "Backports setup and package install", - "type": "object", - "properties": { - "plugins": { - "type": "object", - "properties": { - "sed": { - "type": "object", - "properties": { - "file": { - "type": "string" - }, - "find": { - "type": "string" - }, - "replace": { - "type": "string" - } - } - } - }, - "required": ["sed"] - } - }, - "required": ["plugins"] -} diff --git a/plugins/sed/tasks.py b/plugins/sed/tasks.py deleted file mode 100644 index e71618e..0000000 --- a/plugins/sed/tasks.py +++ /dev/null @@ -1,15 +0,0 @@ -from base import Task -from common import phases -from common.tasks.apt import AptUpgrade -from common.tools import sed_i -import os - - -class DoSeds(Task): - description = 'Sedding files' - phase = phases.system_modification - predecessors = [AptUpgrade] - - def run(self, info): - chroot_path = os.path.join(info.root, info.manifest.plugins['sed']['file']) - sed_i(chroot_path, info.manifest.plugins['sed']['find'], info.manifest.plugins['sed']['replace'])