From eb951f1c2a1915abe6f44599fabd8bb934d93fc1 Mon Sep 17 00:00:00 2001
From: Louis Tu <92532497+tu1h@users.noreply.github.com>
Date: Wed, 3 May 2023 03:00:16 +0800
Subject: [PATCH] update rhsm repo trigger (#10001)

Signed-off-by: tu1h <lihai.tu@daocloud.io>
---
 roles/bootstrap-os/tasks/bootstrap-redhat.yml | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/roles/bootstrap-os/tasks/bootstrap-redhat.yml b/roles/bootstrap-os/tasks/bootstrap-redhat.yml
index e48f5680e..c519ee504 100644
--- a/roles/bootstrap-os/tasks/bootstrap-redhat.yml
+++ b/roles/bootstrap-os/tasks/bootstrap-redhat.yml
@@ -26,7 +26,7 @@
 - name: Check RHEL subscription-manager status
   command: /sbin/subscription-manager status
   register: rh_subscription_status
-  changed_when: "rh_subscription_status != 0"
+  changed_when: "rh_subscription_status.rc != 0"
   ignore_errors: true  # noqa ignore-errors
   become: true
 
@@ -43,7 +43,6 @@
       service_level_agreement: "{{ rh_subscription_sla }}"
       sync: true
   notify: RHEL auto-attach subscription
-  ignore_errors: true  # noqa ignore-errors
   become: true
   when:
     - rh_subscription_org_id is defined
@@ -63,7 +62,6 @@
       service_level_agreement: "{{ rh_subscription_sla }}"
       sync: true
   notify: RHEL auto-attach subscription
-  ignore_errors: true  # noqa ignore-errors
   become: true
   no_log: "{{ not (unsafe_show_logs|bool) }}"
   when:
@@ -79,6 +77,7 @@
     state: "{{ 'enabled' if (rhel_enable_repos | default(True) | bool) else 'disabled' }}"
   when:
     - ansible_distribution_major_version == "7"
+    - (not rh_subscription_status.changed) or (rh_subscription_username is defined) or (rh_subscription_org_id is defined)
 
 # container-selinux is in appstream repo
 - name: Enable RHEL 8 repos
@@ -89,6 +88,7 @@
     state: "{{ 'enabled' if (rhel_enable_repos | default(True) | bool) else 'disabled' }}"
   when:
     - ansible_distribution_major_version == "8"
+    - (not rh_subscription_status.changed) or (rh_subscription_username is defined) or (rh_subscription_org_id is defined)
 
 - name: Check presence of fastestmirror.conf
   stat:
-- 
GitLab