lines = [str(l) for l in new_lines]
- util.write_file(ssh_util.DEF_SSHD_CFG, "\n".join(lines))
+ util.write_file(ssh_util.DEF_SSHD_CFG, "\n".join(lines),
+ copy_mode=True)
try:
cmd = cloud.distro.init_cmd # Default service
This handles the changed mode but it doesn't change the fact that cloud-init strips the newline on the last line. Aside from needlessly modifying the file, it leaves it non-POSIX-compliant (lines in a text file end with a newline).
I see that
commit 721348a622a660b 65acfdf7fdf5320 3b47f80748
Author: Lars Kellogg-Stedman
has added copy_mode to util.write_file, which is nice, and which has been pushed as an update to Xenial.
diff --git a/cloudinit/ config/ cc_set_ passwords. py b/cloudinit/ config/ cc_set_ passwords. py config/ cc_set_ passwords. py config/ cc_set_ passwords. py
pw_ auth))
index eb0bdab0..bb24d57f 100755
--- a/cloudinit/
+++ b/cloudinit/
@@ -215,7 +215,8 @@ def handle(_name, cfg, cloud, log, args):
lines = [str(l) for l in new_lines] file(ssh_ util.DEF_ SSHD_CFG, "\n".join(lines)) file(ssh_ util.DEF_ SSHD_CFG, "\n".join(lines),
- util.write_
+ util.write_
+ copy_mode=True)
try: init_cmd # Default service
cmd = cloud.distro.
This handles the changed mode but it doesn't change the fact that cloud-init strips the newline on the last line. Aside from needlessly modifying the file, it leaves it non-POSIX-compliant (lines in a text file end with a newline).
Just inserting ."\n" to get
would fix the problem.
Attaching diff.