Merge pull request #315 from thepwagner/cloud-init-groups

cloud-init: modify groups
This commit is contained in:
Anders Ingemann 2016-05-22 08:55:18 +02:00
commit 65ad0a43fa
4 changed files with 25 additions and 0 deletions

View file

@ -13,6 +13,9 @@ Settings
- ``username``: The username of the account to create.
``required``
- ``groups``: A list of strings specifying which additional groups the account
should be added to.
``optional``
- ``disable_modules``: A list of strings specifying which cloud-init
modules should be disabled.
``optional``

View file

@ -24,6 +24,8 @@ def resolve_tasks(taskset, manifest):
options = manifest.plugins['cloud_init']
if 'username' in options:
taskset.add(tasks.SetUsername)
if 'groups' in options and len(options['groups']):
taskset.add(tasks.SetGroups)
if 'disable_modules' in options:
taskset.add(tasks.DisableModules)

View file

@ -22,6 +22,10 @@ properties:
type: object
properties:
username: {type: string}
groups:
type: array
items: {type: string}
uniqueItems: true
metadata_sources: {type: string}
disable_modules:
type: array

View file

@ -38,6 +38,22 @@ class SetUsername(Task):
sed_i(cloud_cfg, search, replace)
class SetGroups(Task):
description = 'Setting groups in cloud.cfg'
phase = phases.system_modification
@classmethod
def run(cls, info):
from bootstrapvz.common.tools import sed_i
cloud_cfg = os.path.join(info.root, 'etc/cloud/cloud.cfg')
groups = info.manifest.plugins['cloud_init']['groups']
search = ('^ groups: \[adm, audio, cdrom, dialout, floppy, video,'
' plugdev, dip\]$')
replace = (' groups: [adm, audio, cdrom, dialout, floppy, video,'
' plugdev, dip, {groups}]').format(groups=', '.join(groups))
sed_i(cloud_cfg, search, replace)
class SetMetadataSource(Task):
description = 'Setting metadata source'
phase = phases.package_installation