From 21bea9dc8f3828b4ff169a42c249e93395bbcd25 Mon Sep 17 00:00:00 2001 From: Sorin Sbarnea Date: Mon, 13 May 2024 14:57:06 +0100 Subject: [PATCH] Avoid key exception during transform Related: #4148 --- src/ansiblelint/rules/key_order.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/ansiblelint/rules/key_order.py b/src/ansiblelint/rules/key_order.py index 2a58b8c0be..2d508073dc 100644 --- a/src/ansiblelint/rules/key_order.py +++ b/src/ansiblelint/rules/key_order.py @@ -129,12 +129,16 @@ def transform( if match.tag == f"{self.id}[play]": play = self.seek(match.yaml_path, data) for key in match.transform_meta.fixed: - play[key] = play.pop(key) + # other tansformation might change the key + if key in play: + play[key] = play.pop(key) match.fixed = True if match.tag == f"{self.id}[task]": task = self.seek(match.yaml_path, data) for key in match.transform_meta.fixed: - task[key] = task.pop(key) + # other tansformation might change the key + if key in task: + task[key] = task.pop(key) match.fixed = True