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