Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix play condition in loader to handle playbooks with wrong keywords #207

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions ansible_risk_insight/model_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading