From 9674b5f000cdd0f4a1ac523c32a6dd3ba261bc1c Mon Sep 17 00:00:00 2001 From: hirokuni-kitahara Date: Wed, 1 Nov 2023 09:23:36 +0900 Subject: [PATCH] fix play condition in loader to handle playbooks with wrong keywords Signed-off-by: hirokuni-kitahara --- ansible_risk_insight/model_loader.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/ansible_risk_insight/model_loader.py b/ansible_risk_insight/model_loader.py index 77775b6a..3f091d1f 100644 --- a/ansible_risk_insight/model_loader.py +++ b/ansible_risk_insight/model_loader.py @@ -414,8 +414,17 @@ def load_play( if not isinstance(play_block_dict, dict): raise PlaybookFormatError("this play block is not loaded as dict; maybe this is not a" " playbook") data_block = play_block_dict - if "hosts" not in data_block and "import_playbook" not in data_block and "include" not in data_block: - raise PlaybookFormatError('this play block does not have "hosts", "import_playbook" and' ' "include"; maybe this is not a playbook') + play_keywords = [ + "hosts", + "import_playbook", + "include", + "tasks", + "pre_tasks", + "post_tasks", + ] + could_be_play = any([k in data_block for k in play_keywords]) + if not could_be_play: + raise PlaybookFormatError(f"this play block does not have any of the following keywords {play_keywords}; maybe this is not a playbook") pbObj.index = index pbObj.role = role_name