From fbdb00c052e523a82cdb02199bc782f5775e9d3d Mon Sep 17 00:00:00 2001 From: Bill Wei Date: Fri, 10 Feb 2023 16:46:57 -0500 Subject: [PATCH] Honor limit set in run_job_template's job_args.limit field hosts defined in this field should overwrite rulebook's hosts field but yield to hosts in event's meta field Resolves AAP-9218 --- ansible_rulebook/engine.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/ansible_rulebook/engine.py b/ansible_rulebook/engine.py index 538c6610..04155e72 100644 --- a/ansible_rulebook/engine.py +++ b/ansible_rulebook/engine.py @@ -21,6 +21,7 @@ from pprint import PrettyPrinter, pformat from typing import Any, Dict, List, Optional, cast +import dpath from drools import ruleset as lang from drools.dispatch import establish_async_channel, handle_async_messages from drools.exceptions import ( @@ -362,6 +363,17 @@ async def _call_action( result = None if action in builtin_actions: try: + if action == "run_job_template": + limit = dpath.get( + action_args, + "job_args.limit", + separator=".", + default=None, + ) + if isinstance(limit, list): + hosts = limit + elif isinstance(limit, str): + hosts = [limit] single_match = None keys = list(rules_engine_result.data.keys()) if len(keys) == 0: