mirror of
https://github.com/kevingruesser/bootstrap-vz.git
synced 2025-08-22 09:50:37 +00:00
Support auto-configure of cloud-init data sources, with manual override; support specifying modules to disable.
This commit is contained in:
parent
682b747efc
commit
02ef8cabb8
6 changed files with 60 additions and 6 deletions
|
@ -45,7 +45,8 @@
|
|||
},
|
||||
"cloud_init": {
|
||||
"username": "admin",
|
||||
"metadata_sources": "Ec2"
|
||||
//"metadata_sources": "Ec2",
|
||||
"disable_modules": [ "landscape", "byobu", "ssh-import-id" ]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -45,7 +45,8 @@
|
|||
},
|
||||
"cloud_init": {
|
||||
"username": "admin",
|
||||
"metadata_sources": "Ec2"
|
||||
//"metadata_sources": "Ec2",
|
||||
"disable_modules": [ "landscape", "byobu", "ssh-import-id" ]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -45,7 +45,8 @@
|
|||
},
|
||||
"cloud_init": {
|
||||
"username": "admin",
|
||||
"metadata_sources": "Ec2"
|
||||
//"metadata_sources": "Ec2",
|
||||
"disable_modules": [ "landscape", "byobu", "ssh-import-id" ]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -23,9 +23,11 @@ def validate_manifest(data, schema_validate):
|
|||
def resolve_tasks(tasklist, manifest):
|
||||
from tasks import SetUsername
|
||||
from tasks import SetMetadataSource
|
||||
from tasks import AutoSetMetadataSource
|
||||
from tasks import DisableModules
|
||||
from providers.ec2.tasks.initd import AddEC2InitScripts
|
||||
from common.tasks import initd
|
||||
tasklist.add(SetUsername, SetMetadataSource)
|
||||
tasklist.add(SetUsername, AutoSetMetadataSource, SetMetadataSource, DisableModules)
|
||||
tasklist.remove(AddEC2InitScripts,
|
||||
initd.AddExpandRoot,
|
||||
initd.AdjustExpandRootScript,
|
||||
|
|
|
@ -12,6 +12,13 @@
|
|||
"username": {
|
||||
"type": "string"
|
||||
},
|
||||
"disable_modules": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "string"
|
||||
},
|
||||
"uniqueItems": true
|
||||
},
|
||||
"metadata_sources": {
|
||||
"type": "string"
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@ from common import phases
|
|||
from plugins.packages.tasks import InstallRemotePackages
|
||||
from common.tasks import apt
|
||||
from common.tools import log_check_call
|
||||
import re
|
||||
|
||||
|
||||
class SetUsername(Task):
|
||||
|
@ -28,6 +29,47 @@ class SetMetadataSource(Task):
|
|||
successors = [apt.AptUpdate]
|
||||
|
||||
def run(self, info):
|
||||
sources = "cloud-init cloud-init/datasources multiselect " + info.manifest.plugins['cloud_init']['metadata_sources']
|
||||
log_check_call(['/usr/sbin/chroot', info.root, '/usr/bin/debconf-set-selections' ], sources)
|
||||
if "metadata_sources" in info.manifest.plugins['cloud_init']:
|
||||
sources = "cloud-init cloud-init/datasources multiselect " + info.manifest.plugins['cloud_init']['metadata_sources']
|
||||
log_check_call(['/usr/sbin/chroot', info.root, '/usr/bin/debconf-set-selections' ], sources)
|
||||
|
||||
|
||||
class AutoSetMetadataSource(Task):
|
||||
description = 'Auto-setting metadata source'
|
||||
phase = phases.system_modification
|
||||
predecessors = [apt.AptSources]
|
||||
successors = [SetMetadataSource]
|
||||
def run(self, info):
|
||||
sources = ""
|
||||
if info.manifest.provider == "ec2":
|
||||
sources = "Ec2"
|
||||
|
||||
if sources:
|
||||
sources = "cloud-init cloud-init/datasources multiselect " + sources
|
||||
log_check_call(['/usr/sbin/chroot', info.root, '/usr/bin/debconf-set-selections' ], sources)
|
||||
|
||||
class DisableModules(Task):
|
||||
description = 'Setting cloud.cfg modules'
|
||||
phase = phases.system_modification
|
||||
predecessors = [apt.AptUpgrade]
|
||||
|
||||
def run(self, info):
|
||||
patterns = ""
|
||||
for pattern in info.manifest.plugins['cloud_init']['disable_modules']:
|
||||
if patterns != "":
|
||||
patterns = patterns + "|" + pattern
|
||||
else:
|
||||
patterns = "^\s+-\s+(" + pattern
|
||||
patterns = patterns + ")$"
|
||||
regex = re.compile(patterns)
|
||||
|
||||
f = open(info.root + "/etc/cloud/cloud.cfg")
|
||||
lines = f.readlines()
|
||||
f.close()
|
||||
|
||||
print("Pattern to match is " + patterns + "\n")
|
||||
f = open(info.root + "/etc/cloud/cloud.cfg", "w")
|
||||
for line in lines:
|
||||
if not regex.match(line):
|
||||
f.write(line)
|
||||
f.close
|
||||
|
|
Loading…
Add table
Reference in a new issue