Comment 3 for bug 1677205

Revision history for this message
Lorens Kockum (lorensk) wrote :

I see that

commit 721348a622a660b65acfdf7fdf53203b47f80748
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
index eb0bdab0..bb24d57f 100755
--- a/cloudinit/config/cc_set_passwords.py
+++ b/cloudinit/config/cc_set_passwords.py
@@ -215,7 +215,8 @@ def handle(_name, cfg, cloud, log, args):
                                                      pw_auth))

         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).

Just inserting ."\n" to get

        util.write_file(ssh_util.DEF_SSHD_CFG, "\n".join(lines)."\n",
                        copy_mode=True)

would fix the problem.

Attaching diff.