Blob Blame History Raw
From 528136e7f6c307f035f8db0f14313a213697d2d0 Mon Sep 17 00:00:00 2001
From: Emanuele Giuseppe Esposito <eesposit@redhat.com>
Date: Thu, 8 Sep 2022 17:42:26 +0200
Subject: [PATCH] cloud.cfg.tmpl: make sure "centos" settings are identical to
 "rhel" (#1639)

RH-Author: Emanuele Giuseppe Esposito <eesposit@redhat.com>
RH-MergeRequest: 83: cloud.cfg.tmpl: make sure "centos" settings are identical to "rhel" (#1639)
RH-Bugzilla: 2115576
RH-Acked-by: Camilla Conte <cconte@redhat.com>
RH-Acked-by: Jon Maloy <jmaloy@redhat.com>
RH-Commit: [1/1] f503ce4f79b7d783cd0a4e1ed0977e63a4715031

Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2115576

commit 7593243a1abe2ccaf4698579720999380a4da73b
Author: Emanuele Giuseppe Esposito <eesposit@redhat.com>
Date:   Wed Sep 7 14:53:26 2022 +0200

    cloud.cfg.tmpl: make sure "centos" settings are identical to "rhel" (#1639)

    We have a couple of bugs where centos does not have the default user as rhel.
    This PR makes sure the configuration is exactly the same.

    Signed-off-by: Emanuele Giuseppe Esposito <eesposit@redhat.com>

    RHBZ: 2115565
    RHBZ: 2115576
    Conflicts:
            config/cloud.cfg.tmpl: "openmandriva" distro added in the options

Signed-off-by: Emanuele Giuseppe Esposito <eesposit@redhat.com>
---
 config/cloud.cfg.tmpl                   | 27 +++++++++++++------------
 tests/unittests/test_render_cloudcfg.py |  1 +
 2 files changed, 15 insertions(+), 13 deletions(-)

diff --git a/config/cloud.cfg.tmpl b/config/cloud.cfg.tmpl
index 80ab4f96..08b6efbc 100644
--- a/config/cloud.cfg.tmpl
+++ b/config/cloud.cfg.tmpl
@@ -2,6 +2,7 @@
 # The top level settings are used as module
 # and system configuration.
 {% set is_bsd = variant in ["dragonfly", "freebsd", "netbsd", "openbsd"] %}
+{% set is_rhel = variant in ["rhel", "centos"] %}
 {% if is_bsd %}
 syslog_fix_perms: root:wheel
 {% elif variant in ["suse"] %}
@@ -32,9 +33,9 @@ disable_root: false
 disable_root: true
 {% endif %}
 
-{% if variant in ["almalinux", "alpine", "amazon", "centos", "cloudlinux", "eurolinux",
-                  "fedora", "miraclelinux", "openEuler", "rhel", "rocky", "virtuozzo"] %}
-{% if variant == "rhel" %}
+{% if variant in ["almalinux", "alpine", "amazon", "cloudlinux", "eurolinux",
+                  "fedora", "miraclelinux", "openEuler", "openmandriva", "rocky", "virtuozzo"] or is_rhel %}
+{% if is_rhel %}
 mount_default_fields: [~, ~, 'auto', 'defaults,nofail,x-systemd.requires=cloud-init.service,_netdev', '0', '2']
 {% else %}
 mount_default_fields: [~, ~, 'auto', 'defaults,nofail', '0', '2']
@@ -70,7 +71,7 @@ network:
   config: disabled
 {% endif %}
 
-{% if variant == "rhel" %}
+{% if is_rhel %}
 # Default redhat settings:
 ssh_deletekeys:   true
 ssh_genkeytypes:  ['rsa', 'ecdsa', 'ed25519']
@@ -119,16 +120,16 @@ cloud_config_modules:
 {% endif %}
 {% if variant not in ["photon"] %}
  - ssh-import-id
-{% if variant not in ["rhel"] %}
+{% if not is_rhel %}
  - keyboard
 {% endif %}
  - locale
 {% endif %}
  - set-passwords
-{% if variant in ["rhel"] %}
+{% if is_rhel %}
  - rh_subscription
 {% endif %}
-{% if variant in ["rhel", "fedora", "photon"] %}
+{% if variant in ["fedora", "openmandriva", "photon"] or is_rhel %}
 {% if variant not in ["photon"] %}
  - spacewalk
 {% endif %}
@@ -193,9 +194,9 @@ cloud_final_modules:
 # (not accessible to handlers/transforms)
 system_info:
    # This will affect which distro class gets used
-{% if variant in ["almalinux", "alpine", "amazon", "arch", "centos", "cloudlinux", "debian",
+{% if variant in ["almalinux", "alpine", "amazon", "arch", "cloudlinux", "debian",
                   "eurolinux", "fedora", "freebsd", "gentoo", "netbsd", "miraclelinux", "openbsd", "openEuler",
-                  "photon", "rhel", "rocky", "suse", "ubuntu", "virtuozzo"] %}
+                  "openmandriva", "photon", "rocky", "suse", "ubuntu", "virtuozzo"] or is_rhel %}
    distro: {{ variant }}
 {% elif variant in ["dragonfly"] %}
    distro: dragonflybsd
@@ -248,15 +249,15 @@ system_info:
          primary: http://ports.ubuntu.com/ubuntu-ports
          security: http://ports.ubuntu.com/ubuntu-ports
    ssh_svcname: ssh
-{% elif variant in ["almalinux", "alpine", "amazon", "arch", "centos", "cloudlinux", "eurolinux",
-                    "fedora", "gentoo", "miraclelinux", "openEuler", "rhel", "rocky", "suse", "virtuozzo"] %}
+{% elif variant in ["almalinux", "alpine", "amazon", "arch", "cloudlinux", "eurolinux",
+                    "fedora", "gentoo", "miraclelinux", "openEuler", "openmandriva", "rocky", "suse", "virtuozzo"] or is_rhel %}
    # Default user name + that default users groups (if added/used)
    default_user:
 {% if variant == "amazon" %}
      name: ec2-user
      lock_passwd: True
      gecos: EC2 Default User
-{% elif variant == "rhel" %}
+{% elif is_rhel %}
      name: cloud-user
      lock_passwd: true
      gecos: Cloud User
@@ -275,7 +276,7 @@ system_info:
      groups: [adm, sudo]
 {% elif variant == "arch" %}
      groups: [wheel, users]
-{% elif variant == "rhel" %}
+{% elif is_rhel %}
      groups: [adm, systemd-journal]
 {% else %}
      groups: [wheel, adm, systemd-journal]
diff --git a/tests/unittests/test_render_cloudcfg.py b/tests/unittests/test_render_cloudcfg.py
index 9f95d448..1a6e2715 100644
--- a/tests/unittests/test_render_cloudcfg.py
+++ b/tests/unittests/test_render_cloudcfg.py
@@ -69,6 +69,7 @@ class TestRenderCloudCfg:
             "amazon": "ec2-user",
             "debian": "ubuntu",
             "rhel": "cloud-user",
+            "centos": "cloud-user",
             "unknown": "ubuntu",
         }
         default_user = system_cfg["system_info"]["default_user"]["name"]
-- 
2.37.3