From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 036C870824 for ; Mon, 28 Jul 2025 00:18:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.137.202.133 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1753661889; cv=none; b=MLmr3MYlrsn2mvJZ2hBXj8OXeyAJ2AI3MRvu/igNzsPZdBcWEn8mboZPxSlIF6JTXLPSNKnelkX3J2VJ2EA9GKo1sqon/8c1I1xjNERW4lqbb0hNW5wHUUeGofSxUczEJCMwPhoW7RqTCn5uJmWjNzlyBN7BTxKS+Ns7bbFTMso= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1753661889; c=relaxed/simple; bh=c5akjaCGMxtoMqVLfmLeciN34zD2wczZL0EooqJZwbg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ZCDl4RHzjadx7WqQ2CbiOAnPaDswAFVkaYi9G0z8Ns2LliYVGjGkBs5+PccUGzKmNHPpMqiRiUS50E4/t2wN3UGpSCPlhvO8s0neKRkX3ndbJmqs3rjMkZSAoEFPUCaE472sPKBNLY+Yd9g2rQYvE4DMnFMPM3GV0daHe1E2jik= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=kernel.org; spf=none smtp.mailfrom=infradead.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b=ZGYu9dB9; arc=none smtp.client-ip=198.137.202.133 Authentication-Results: smtp.subspace.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=kernel.org Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=infradead.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="ZGYu9dB9" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Sender:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description; bh=C4JSJ4HHVxveitCjUXnH4e/08G9Qi9c8m3MhVdHWrGI=; b=ZGYu9dB9cOQ60kWb2vsF82UyB0 WB0MNpgfP72zhuGwempMDewtGn56DCS4fcWiCg0Hgy5MxfILtk84XZkue465tKEbM52XXzGZP1URx ATmT1Ecvv7SD01PJ/K7GrpEug0zywhOzhhDS+Eovws05/Z/KgvNSdeDKJE7egOTDKVkAG3iaF9wQh sIN6tBl6MptZ4syK9l6/MadG2hy8jbKjW1+UEx592S5uOmSknaEjjvZ8K30KIP/8gq1Vwrz04vXYC CueeQFP0584Hfv1BcUbzAdT/zzG9qsbApEHB4pB7k2FZ3Tp8vfUGN31pHvGXK/F/tWuRZ4vlO67rv Q3qL9v7Q==; Received: from mcgrof by bombadil.infradead.org with local (Exim 4.98.2 #2 (Red Hat Linux)) id 1ugBZ5-0000000DNXm-0CTJ; Mon, 28 Jul 2025 00:18:03 +0000 From: Luis Chamberlain To: Chuck Lever , Daniel Gomez , kdevops@lists.linux.dev Cc: Luis Chamberlain Subject: [PATCH 28/40] bootlinux: fix grub_boot_number_cmd undefined error in update-grub Date: Sun, 27 Jul 2025 17:17:47 -0700 Message-ID: <20250728001800.3188617-29-mcgrof@kernel.org> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250728001800.3188617-1-mcgrof@kernel.org> References: <20250728001800.3188617-1-mcgrof@kernel.org> Precedence: bulk X-Mailing-List: kdevops@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: Luis Chamberlain The update-grub/install.yml playbook was failing with: "The conditional check 'grub_boot_number_cmd.rc == 0' failed. The error was: 'dict object' has no attribute 'rc'" This regression was introduced when the update-grub tasks were hardened to check for kernel_release_file.stat.exists. The hardening correctly added guards for when kernel_release_file might not exist, but it didn't account for the fact that when those conditions aren't met, the grub_boot_number_cmd variable is never registered by the skipped tasks. The original code assumed grub_boot_number_cmd would always be registered, but the new conditional flow creates a path where subsequent tasks try to access grub_boot_number_cmd.rc on an undefined variable, causing the playbook to fail. This commit adds defensive checks to ensure grub_boot_number_cmd and its attributes are defined before accessing them. It also adds safe fallbacks in the vars sections to prevent template errors when the variable is undefined. The fix allows the playbook to gracefully skip setting the default boot kernel when the kernel release information isn't available, rather than failing with an undefined variable error. Fixes: fa805e807fad ("bootlinux: Harden update-grub/install.yml") Generated-by: Claude AI Signed-off-by: Luis Chamberlain --- playbooks/roles/bootlinux/tasks/update-grub/install.yml | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/playbooks/roles/bootlinux/tasks/update-grub/install.yml b/playbooks/roles/bootlinux/tasks/update-grub/install.yml index af90008b..38ec8c76 100644 --- a/playbooks/roles/bootlinux/tasks/update-grub/install.yml +++ b/playbooks/roles/bootlinux/tasks/update-grub/install.yml @@ -186,10 +186,13 @@ become_method: sudo command: "{{ grub_set_default_boot_kernel }} \"{{ target_boot_entry }}\"" vars: - target_boot_entry: "{{ grub_boot_number_cmd.stdout_lines.0 }}" + target_boot_entry: "{{ grub_boot_number_cmd.stdout_lines.0 if (grub_boot_number_cmd is defined and grub_boot_number_cmd.stdout_lines is defined) else '' }}" tags: [ 'saved' ] when: + - grub_boot_number_cmd is defined + - grub_boot_number_cmd.rc is defined - grub_boot_number_cmd.rc == 0 + - grub_boot_number_cmd.stdout is defined - grub_boot_number_cmd.stdout != "" - name: Itemize kernel and GRUB entry we just selected @@ -200,6 +203,9 @@ target_boot_entry: "{{ grub_boot_number_cmd.stdout_lines.0 }}" tags: [ 'saved' ] when: + - grub_boot_number_cmd is defined + - grub_boot_number_cmd.rc is defined - grub_boot_number_cmd.rc == 0 + - grub_boot_number_cmd.stdout is defined - grub_boot_number_cmd.stdout != "" -- 2.47.2