summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAni Sinha <anisinha@redhat.com>2023-04-04 19:59:07 +0530
committerGitHub <noreply@github.com>2023-04-04 16:29:07 +0200
commit6d42aa8e2c1a5454a658ab4e2b9cead2677c77cd (patch)
tree604e5750ef245de0cd74a5aa6566fbe84767db3a
parent55eaba2f576cd1c51ab3791906d8698791a4b68a (diff)
downloadcloud-init-git-6d42aa8e2c1a5454a658ab4e2b9cead2677c77cd.tar.gz
rhel: make sure previous-hostname file ends with a new line (#2108)
cloud-init strips new line from "/etc/hostname" on rhel distro when processing "/var/lib/cloud/data/previous-hostname". Although this does not pose a serious issue, it is still better if the behavior is similar to other distros like Ubuntu where /previous-hostname does end with a new line. Fix this issue by using hostname parser in rhel similar to debian. Signed-off-by: Ani Sinha <anisinha@redhat.com>
-rw-r--r--cloudinit/distros/rhel.py5
-rw-r--r--tools/.github-cla-signers1
2 files changed, 5 insertions, 1 deletions
diff --git a/cloudinit/distros/rhel.py b/cloudinit/distros/rhel.py
index 7fb7e56d..644422a7 100644
--- a/cloudinit/distros/rhel.py
+++ b/cloudinit/distros/rhel.py
@@ -13,6 +13,7 @@ from cloudinit import distros, helpers
from cloudinit import log as logging
from cloudinit import subp, util
from cloudinit.distros import rhel_util
+from cloudinit.distros.parsers.hostname import HostnameConf
from cloudinit.settings import PER_INSTANCE
LOG = logging.getLogger(__name__)
@@ -104,7 +105,9 @@ class Distro(distros.Distro):
# systemd will never update previous-hostname for us, so
# we need to do it ourselves
if self.uses_systemd() and filename.endswith("/previous-hostname"):
- util.write_file(filename, hostname)
+ conf = HostnameConf("")
+ conf.set_hostname(hostname)
+ util.write_file(filename, str(conf), 0o644)
elif self.uses_systemd():
subp.subp(["hostnamectl", "set-hostname", str(hostname)])
else:
diff --git a/tools/.github-cla-signers b/tools/.github-cla-signers
index 79bac4c5..9403db1a 100644
--- a/tools/.github-cla-signers
+++ b/tools/.github-cla-signers
@@ -10,6 +10,7 @@ andgein
andrew-lee-metaswitch
andrewbogott
andrewlukoshko
+ani-sinha
antonyc
aswinrajamannar
bdrung