sailesh1993 / rpms / cloud-init

Forked from rpms/cloud-init 10 months ago
Clone
59e311
From 8e599c618ba33f7ed572f752fc9201ca44e41868 Mon Sep 17 00:00:00 2001
59e311
From: Emanuele Giuseppe Esposito <eesposit@redhat.com>
59e311
Date: Wed, 18 May 2022 16:21:45 +0200
59e311
Subject: [PATCH 4/5] Align rhel custom files with upstream (#1431)
59e311
59e311
RH-Author: Emanuele Giuseppe Esposito <eesposit@redhat.com>
59e311
RH-MergeRequest: 26: Align rhel custom files with upstream (#1431)
59e311
RH-Commit: [1/2] edac80c4fa3a11d093ee0e7260796566a7eb141e (eesposit/cloud-init-centos-)
59e311
RH-Bugzilla: 2088448
59e311
RH-Acked-by: Vitaly Kuznetsov <vkuznets@redhat.com>
59e311
RH-Acked-by: Miroslav Rezanina <mrezanin@redhat.com>
59e311
59e311
commit 9624758f91b61f4711e8d7b5c83075b5d23e0c43
59e311
Author: Emanuele Giuseppe Esposito <eesposit@redhat.com>
59e311
Date:   Wed May 18 15:18:04 2022 +0200
59e311
59e311
    Align rhel custom files with upstream (#1431)
59e311
59e311
    So far RHEL had its own custom .service and cloud.cfg files,
59e311
    that diverged from upstream. We always replaced the generated files
59e311
    with the ones we had.
59e311
59e311
    This caused only confusion and made it harder to rebase and backport
59e311
    patches targeting these files.
59e311
    At the same time, we are going to delete our custom downstream-only files
59e311
    and use the ones generated by .tmpl.
59e311
59e311
    The mapping is:
59e311
    config/cloud.cfg.tmpl -> rhel/cloud.cfg
59e311
    systemd/* -> rhel/systemd/*
59e311
59e311
    Such rhel-specific files are open and available in the Centos repo:
59e311
    https://gitlab.com/redhat/centos-stream/src/cloud-init
59e311
59e311
    With this commit, we are also introducing modules in cloud.cfg that
59e311
    were not in the default rhel cfg file, even though they should already
59e311
    have been there with previous rebases and releases.
59e311
    Anyways such modules support rhel as distro, and
59e311
    therefore should cause no harm.
59e311
59e311
    Signed-off-by: Emanuele Giuseppe Esposito <eesposit@redhat.com>
59e311
59e311
    RHBZ: 2082071
59e311
59e311
Signed-off-by: Emanuele Giuseppe Esposito <eesposit@redhat.com>
59e311
---
59e311
 config/cloud.cfg.tmpl                   | 23 +++++++++++++++++++++++
59e311
 systemd/cloud-config.service.tmpl       |  4 ++++
59e311
 systemd/cloud-final.service.tmpl        | 13 +++++++++++++
59e311
 systemd/cloud-init-local.service.tmpl   | 22 +++++++++++++++++++++-
59e311
 systemd/cloud-init.service.tmpl         |  6 +++++-
59e311
 tests/unittests/test_render_cloudcfg.py |  1 +
59e311
 6 files changed, 67 insertions(+), 2 deletions(-)
59e311
59e311
diff --git a/config/cloud.cfg.tmpl b/config/cloud.cfg.tmpl
59e311
index 86beee3c..f4d2fd14 100644
59e311
--- a/config/cloud.cfg.tmpl
59e311
+++ b/config/cloud.cfg.tmpl
59e311
@@ -34,7 +34,11 @@ disable_root: true
59e311
 
59e311
 {% if variant in ["almalinux", "alpine", "amazon", "centos", "cloudlinux", "eurolinux",
59e311
                   "fedora", "miraclelinux", "openEuler", "rhel", "rocky", "virtuozzo"] %}
59e311
+{% if variant == "rhel" %}
59e311
+mount_default_fields: [~, ~, 'auto', 'defaults,nofail,x-systemd.requires=cloud-init.service,_netdev', '0', '2']
59e311
+{% else %}
59e311
 mount_default_fields: [~, ~, 'auto', 'defaults,nofail', '0', '2']
59e311
+{% endif %}
59e311
 {% if variant == "amazon" %}
59e311
 resize_rootfs: noblock
59e311
 {% endif %}
59e311
@@ -66,6 +70,14 @@ network:
59e311
   config: disabled
59e311
 {% endif %}
59e311
 
59e311
+{% if variant == "rhel" %}
59e311
+# Default redhat settings:
59e311
+ssh_deletekeys:   true
59e311
+ssh_genkeytypes:  ['rsa', 'ecdsa', 'ed25519']
59e311
+syslog_fix_perms: ~
59e311
+disable_vmware_customization: false
59e311
+{% endif %}
59e311
+
59e311
 # The modules that run in the 'init' stage
59e311
 cloud_init_modules:
59e311
  - migrator
59e311
@@ -107,10 +119,15 @@ cloud_config_modules:
59e311
 {% endif %}
59e311
 {% if variant not in ["photon"] %}
59e311
  - ssh-import-id
59e311
+{% if variant not in ["rhel"] %}
59e311
  - keyboard
59e311
+{% endif %}
59e311
  - locale
59e311
 {% endif %}
59e311
  - set-passwords
59e311
+{% if variant in ["rhel"] %}
59e311
+ - rh_subscription
59e311
+{% endif %}
59e311
 {% if variant in ["rhel", "fedora", "photon"] %}
59e311
 {% if variant not in ["photon"] %}
59e311
  - spacewalk
59e311
@@ -239,6 +256,10 @@ system_info:
59e311
      name: ec2-user
59e311
      lock_passwd: True
59e311
      gecos: EC2 Default User
59e311
+{% elif variant == "rhel" %}
59e311
+     name: cloud-user
59e311
+     lock_passwd: true
59e311
+     gecos: Cloud User
59e311
 {% else %}
59e311
      name: {{ variant }}
59e311
      lock_passwd: True
59e311
@@ -254,6 +275,8 @@ system_info:
59e311
      groups: [adm, sudo]
59e311
 {% elif variant == "arch" %}
59e311
      groups: [wheel, users]
59e311
+{% elif variant == "rhel" %}
59e311
+     groups: [adm, systemd-journal]
59e311
 {% else %}
59e311
      groups: [wheel, adm, systemd-journal]
59e311
 {% endif %}
59e311
diff --git a/systemd/cloud-config.service.tmpl b/systemd/cloud-config.service.tmpl
59e311
index 9d928ca2..d5568a6e 100644
59e311
--- a/systemd/cloud-config.service.tmpl
59e311
+++ b/systemd/cloud-config.service.tmpl
59e311
@@ -4,6 +4,10 @@ Description=Apply the settings specified in cloud-config
59e311
 After=network-online.target cloud-config.target
59e311
 After=snapd.seeded.service
59e311
 Wants=network-online.target cloud-config.target
59e311
+{% if variant == "rhel" %}
59e311
+ConditionPathExists=!/etc/cloud/cloud-init.disabled
59e311
+ConditionKernelCommandLine=!cloud-init=disabled
59e311
+{% endif %}
59e311
 
59e311
 [Service]
59e311
 Type=oneshot
59e311
diff --git a/systemd/cloud-final.service.tmpl b/systemd/cloud-final.service.tmpl
59e311
index 8207b18c..85f423ac 100644
59e311
--- a/systemd/cloud-final.service.tmpl
59e311
+++ b/systemd/cloud-final.service.tmpl
59e311
@@ -7,6 +7,10 @@ After=multi-user.target
59e311
 Before=apt-daily.service
59e311
 {% endif %}
59e311
 Wants=network-online.target cloud-config.service
59e311
+{% if variant == "rhel" %}
59e311
+ConditionPathExists=!/etc/cloud/cloud-init.disabled
59e311
+ConditionKernelCommandLine=!cloud-init=disabled
59e311
+{% endif %}
59e311
 
59e311
 
59e311
 [Service]
59e311
@@ -15,7 +19,16 @@ ExecStart=/usr/bin/cloud-init modules --mode=final
59e311
 RemainAfterExit=yes
59e311
 TimeoutSec=0
59e311
 KillMode=process
59e311
+{% if variant == "rhel" %}
59e311
+# Restart NetworkManager if it is present and running.
59e311
+ExecStartPost=/bin/sh -c 'u=NetworkManager.service; \
59e311
+ out=$(systemctl show --property=SubState $u) || exit; \
59e311
+ [ "$out" = "SubState=running" ] || exit 0; \
59e311
+ systemctl reload-or-try-restart $u'
59e311
+{% else %}
59e311
 TasksMax=infinity
59e311
+{% endif %}
59e311
+
59e311
 
59e311
 # Output needs to appear in instance console output
59e311
 StandardOutput=journal+console
59e311
diff --git a/systemd/cloud-init-local.service.tmpl b/systemd/cloud-init-local.service.tmpl
59e311
index 7166f640..a6b82650 100644
59e311
--- a/systemd/cloud-init-local.service.tmpl
59e311
+++ b/systemd/cloud-init-local.service.tmpl
59e311
@@ -1,23 +1,43 @@
59e311
 ## template:jinja
59e311
 [Unit]
59e311
 Description=Initial cloud-init job (pre-networking)
59e311
-{% if variant in ["ubuntu", "unknown", "debian"] %}
59e311
+{% if variant in ["ubuntu", "unknown", "debian", "rhel" ] %}
59e311
 DefaultDependencies=no
59e311
 {% endif %}
59e311
 Wants=network-pre.target
59e311
 After=hv_kvp_daemon.service
59e311
 After=systemd-remount-fs.service
59e311
+{% if variant == "rhel" %}
59e311
+Requires=dbus.socket
59e311
+After=dbus.socket
59e311
+{% endif %}
59e311
 Before=NetworkManager.service
59e311
+{% if variant == "rhel" %}
59e311
+Before=network.service
59e311
+{% endif %}
59e311
 Before=network-pre.target
59e311
 Before=shutdown.target
59e311
+{% if variant == "rhel" %}
59e311
+Before=firewalld.target
59e311
+Conflicts=shutdown.target
59e311
+{% endif %}
59e311
 {% if variant in ["ubuntu", "unknown", "debian"] %}
59e311
 Before=sysinit.target
59e311
 Conflicts=shutdown.target
59e311
 {% endif %}
59e311
 RequiresMountsFor=/var/lib/cloud
59e311
+{% if variant == "rhel" %}
59e311
+ConditionPathExists=!/etc/cloud/cloud-init.disabled
59e311
+ConditionKernelCommandLine=!cloud-init=disabled
59e311
+{% endif %}
59e311
 
59e311
 [Service]
59e311
 Type=oneshot
59e311
+{% if variant == "rhel" %}
59e311
+ExecStartPre=/bin/mkdir -p /run/cloud-init
59e311
+ExecStartPre=/sbin/restorecon /run/cloud-init
59e311
+ExecStartPre=/usr/bin/touch /run/cloud-init/enabled
59e311
+{% endif %}
59e311
 ExecStart=/usr/bin/cloud-init init --local
59e311
 ExecStart=/bin/touch /run/cloud-init/network-config-ready
59e311
 RemainAfterExit=yes
59e311
diff --git a/systemd/cloud-init.service.tmpl b/systemd/cloud-init.service.tmpl
59e311
index e71e5679..c170aef7 100644
59e311
--- a/systemd/cloud-init.service.tmpl
59e311
+++ b/systemd/cloud-init.service.tmpl
59e311
@@ -1,7 +1,7 @@
59e311
 ## template:jinja
59e311
 [Unit]
59e311
 Description=Initial cloud-init job (metadata service crawler)
59e311
-{% if variant not in ["photon"] %}
59e311
+{% if variant not in ["photon", "rhel"] %}
59e311
 DefaultDependencies=no
59e311
 {% endif %}
59e311
 Wants=cloud-init-local.service
59e311
@@ -36,6 +36,10 @@ Before=shutdown.target
59e311
 Conflicts=shutdown.target
59e311
 {% endif %}
59e311
 Before=systemd-user-sessions.service
59e311
+{% if variant == "rhel" %}
59e311
+ConditionPathExists=!/etc/cloud/cloud-init.disabled
59e311
+ConditionKernelCommandLine=!cloud-init=disabled
59e311
+{% endif %}
59e311
 
59e311
 [Service]
59e311
 Type=oneshot
59e311
diff --git a/tests/unittests/test_render_cloudcfg.py b/tests/unittests/test_render_cloudcfg.py
59e311
index 30fbd1a4..9f95d448 100644
59e311
--- a/tests/unittests/test_render_cloudcfg.py
59e311
+++ b/tests/unittests/test_render_cloudcfg.py
59e311
@@ -68,6 +68,7 @@ class TestRenderCloudCfg:
59e311
         default_user_exceptions = {
59e311
             "amazon": "ec2-user",
59e311
             "debian": "ubuntu",
59e311
+            "rhel": "cloud-user",
59e311
             "unknown": "ubuntu",
59e311
         }
59e311
         default_user = system_cfg["system_info"]["default_user"]["name"]
59e311
-- 
59e311
2.31.1
59e311