cloud-init-dev team mailing list archive
-
cloud-init-dev team
-
Mailing list archive
-
Message #05856
[Merge] ~j.w.baxter/cloud-init:append_files into cloud-init:master
James Baxter has proposed merging ~j.w.baxter/cloud-init:append_files into cloud-init:master.
Commit message:
config: write_files can now append contents
Requested reviews:
cloud-init commiters (cloud-init-dev)
For more details, see:
https://code.launchpad.net/~j.w.baxter/cloud-init/+git/cloud-init/+merge/359975
Adds the ability to append to files
--
Your team cloud-init commiters is requested to review the proposed merge of ~j.w.baxter/cloud-init:append_files into cloud-init:master.
diff --git a/cloudinit/config/cc_write_files.py b/cloudinit/config/cc_write_files.py
index 31d1db6..fb3fbbc 100644
--- a/cloudinit/config/cc_write_files.py
+++ b/cloudinit/config/cc_write_files.py
@@ -49,6 +49,10 @@ binary gzip data can be specified and will be decoded before being written.
...
path: /bin/arch
permissions: '0555'
+ - content: |
+ 15 * * * * root ship_logs
+ path: /etc/crontab
+ append: true
"""
import base64
@@ -113,10 +117,18 @@ def write_files(name, files):
contents = extract_contents(f_info.get('content', ''), extractions)
(u, g) = util.extract_usergroup(f_info.get('owner', DEFAULT_OWNER))
perms = decode_perms(f_info.get('permissions'), DEFAULT_PERMS)
- util.write_file(path, contents, mode=perms)
+ omode = determine_omode(f_info.get('append'))
+ util.write_file(path, contents, omode=omode, mode=perms)
util.chownbyname(path, u, g)
+def determine_omode(append):
+ if append is not None and append.lower() == "true":
+ return "ab"
+ else:
+ return "wb"
+
+
def decode_perms(perm, default):
if perm is None:
return default