from cloudinit.handlers import cloud_config
from cloudinit import handlers
from cloudinit import helpers
from cloudinit import log as logging
logging.setupBasicLogging()
# Put your yaml sections in here...
pieces = []
pieces.append(
"""#cloud-config
merge_how: list(append)+dict(recurse_array)+str()
a: b
c: []
"""
)
pieces.append(
"""#cloud-config
merge_how: list(append)+dict(recurse_array)+str()
c: [1, 2]
"""
)
pieces.append(
"""#cloud-config
merge_how: list(append)+dict(recurse_array)+str()
c: [3, 4]
"""
)
# Set things up...
ctype = handlers.type_from_starts_with(cloud_config.CLOUD_PREFIX)
h = cloud_config.CloudConfigPartHandler(helpers.Paths({}))
h.handle_part("", handlers.CONTENT_START, "", "", "", {})
for p in pieces:
h.handle_part("", ctype, "", p, "", {})
print("Merged result:")
print(h.cloud_buf)