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 25C367082F 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=1753661888; cv=none; b=dRmROzIfS7ja/RF441y+0rQmNZl2fvPo2btXNwGPzZgOlQYLWh1qtWhHOzA/fCChqAXggzL3nwznKajT0X4E8g7eXwvQreEFwWZ619KwzRa+xPkZN3ZHy34kDyYqs/2tRU/VeEqSiI9OvBpPxJt2g7vnVPKo7la5E9GU+uETTkU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1753661888; c=relaxed/simple; bh=Hio7MpOJMNzY7tg44H9OjvO5b9FFzULa5j+vYRB7fT4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=NK/6m7/3T4q/eC+i/f8HexRjUSnT8s2qtCe58VKqmukRzJgvCi2XgYWT0lxGVkFRkSHUjQB/oD4cNDFOaCI5mllhpPGio4j6U+83mBDqyQkFrREoj8hZpa2E+ha2VmUqwk4OPywqRyWtaQPPwC2dPEslOCaHwJjdXaeCWPXC3Vw= 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=eeMp1ZHy; 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="eeMp1ZHy" 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=TwDwXH759/j/K2Oj4Tb5v0Sl9Pc3/RsPU+ttUFhVaQ8=; b=eeMp1ZHywi8amFu7wZa1JOA49f ct4EGuosVcjrVuaa8ANOOdg5odgn32Yz9Y9wJ1z5TdyGecUCgGewgiTbnZG03kfQnVhi6NqQxuuj1 yMgGq4xtHDRsDW6c83a2+U0vp6dUSY5SQ2+sNXTJDBUl8Qx2vypqupIWB/AF4tu+aEEruKZ5idToL Alt9a3I+I/IBw0UPzjaO4LSq0M62FC500BzZseg58zxLq8VK3mvMpNkkhKX/rs9yL2QusN9n9b+KO y3VNcRDVIm9Fx22/2F7P32tRONrYKtS7Nt5DJ52DB+slxDS1sS1ipnzJY3w87Bg8qHO+o8F4fZgJd TSvEtjtg==; Received: from mcgrof by bombadil.infradead.org with local (Exim 4.98.2 #2 (Red Hat Linux)) id 1ugBZ5-0000000DNXq-0f7x; 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 29/40] bootlinux: fix kernel_release_file.stat undefined error in update-grub Date: Sun, 27 Jul 2025 17:17:48 -0700 Message-ID: <20250728001800.3188617-30-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 'kernel_release_file.stat.exists' failed. The error was: 'dict object' has no attribute 'stat'" This regression was introduced when the update-grub tasks were hardened. The hardening added multiple instances of checking kernel_release_file.stat.exists throughout the playbook, but these checks assumed that the stat task would always run and populate the kernel_release_file variable with a stat attribute. However, when certain conditions aren't met (e.g., when using pre-built packages or when the kernel hasn't been built yet), the stat task itself might be skipped or fail, leaving kernel_release_file without the expected stat attribute. The hardening didn't account for this possibility, causing the playbook to fail when trying to access .stat on an incomplete variable structure. This commit adds: 1. Defensive checks for kernel_release_file and its stat attribute before accessing .exists 2. A default kernelrelease value of "unknown" when it can't be determined 3. Additional checks to ensure kernelrelease is defined and not "unknown" before using it in grep commands These changes prevent the playbook from failing when the kernel release file doesn't exist or can't be read, allowing it to gracefully skip the grub default kernel setting steps. Fixes: fa805e807fad ("bootlinux: Harden update-grub/install.yml") Generated-by: Claude AI Signed-off-by: Luis Chamberlain --- .../bootlinux/tasks/update-grub/install.yml | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/playbooks/roles/bootlinux/tasks/update-grub/install.yml b/playbooks/roles/bootlinux/tasks/update-grub/install.yml index 38ec8c76..a10064ee 100644 --- a/playbooks/roles/bootlinux/tasks/update-grub/install.yml +++ b/playbooks/roles/bootlinux/tasks/update-grub/install.yml @@ -117,6 +117,12 @@ when: - kernel_release_file.stat.exists +- name: Set default kernelrelease if not determined + ansible.builtin.set_fact: + kernelrelease: "unknown" + when: + - kernelrelease is not defined + - name: Get the kernel release of the kernel to be installed tags: - vars @@ -134,7 +140,11 @@ /boot/grub/grub.cfg | awk '{print NR-1" ... "$0}' | grep {{ kernelrelease }} | head -1 | awk '{print $1}' when: + - kernel_release_file is defined + - kernel_release_file.stat is defined - kernel_release_file.stat.exists + - kernelrelease is defined + - kernelrelease != "unknown" - ansible_os_family != "RedHat" or ansible_distribution_major_version | int < 8 - name: Construct the command line to determine default boot entry for RHEL >= 8 @@ -146,7 +156,11 @@ cat $f; done | grep title | awk '{ gsub("title ", "", $0); print }' | grep '{{ kernelrelease }}'; when: + - kernel_release_file is defined + - kernel_release_file.stat is defined - kernel_release_file.stat.exists + - kernelrelease is defined + - kernelrelease != "unknown" - ansible_os_family == "RedHat" - ansible_distribution_major_version | int >= 8 @@ -166,6 +180,8 @@ register: grub_boot_number_cmd changed_when: false when: + - kernel_release_file is defined + - kernel_release_file.stat is defined - kernel_release_file.stat.exists - name: Obtain command to set default kernel to boot -- 2.47.2