diff --git a/ansible_rulebook/builtin.py b/ansible_rulebook/builtin.py index 4dfd9653..0f8e5d1c 100644 --- a/ansible_rulebook/builtin.py +++ b/ansible_rulebook/builtin.py @@ -834,9 +834,5 @@ def _collect_extra_vars( eda_vars["events"] = variables["events"] if "event" in variables: eda_vars["event"] = variables["event"] - if "facts" in variables: - eda_vars["facts"] = variables["events"] - if "fact" in variables: - eda_vars["fact"] = variables["event"] extra_vars[KEY_EDA_VARS] = eda_vars return extra_vars diff --git a/ansible_rulebook/engine.py b/ansible_rulebook/engine.py index 9a88c8da..b4ad3b70 100644 --- a/ansible_rulebook/engine.py +++ b/ansible_rulebook/engine.py @@ -385,14 +385,12 @@ async def _call_action( variables_copy = variables.copy() if single_match is not None: variables_copy["event"] = single_match - variables_copy["fact"] = single_match event = single_match if "meta" in event: if "hosts" in event["meta"]: hosts = parse_hosts(event["meta"]["hosts"]) else: variables_copy["events"] = multi_match - variables_copy["facts"] = multi_match new_hosts = [] for event in variables_copy["events"].values(): if "meta" in event: diff --git a/docs/events_and_facts.rst b/docs/events_and_facts.rst index 94ed69ef..cce2751b 100644 --- a/docs/events_and_facts.rst +++ b/docs/events_and_facts.rst @@ -40,11 +40,11 @@ Instead, the ``all`` operator must be used: .. note:: - To use facts you may use either ``event`` or ``facts`` keys interchangeably. + To use facts you may use either ``events`` or ``facts`` keys interchangeably. You can combine `set_fact `_ and `retract_fact `_ actions to manage the global state during the lifecycle of your rulebook. The text above describes how to use ``events`` or ``facts`` in a rulebook. A single matched ``event`` or multiple matched ``events`` are also sent to a playbook through extra_vars under namespace ``ansible_eda`` when a run_playbook or run_job_template action is executed. So in a playbook -you should reference them as ``ansible_eda.event`` or ``ansible_eda.events``. +you should reference them as ``ansible_eda.event`` or ``ansible_eda.events``. Facts are not sent to playbooks. diff --git a/tests/asts/test_set_facts.yml b/tests/asts/test_set_facts.yml index 6c1b119f..e9ac4be1 100644 --- a/tests/asts/test_set_facts.yml +++ b/tests/asts/test_set_facts.yml @@ -32,10 +32,10 @@ name: playbooks/validate_args_playbook.yml extra_vars: my_vars: - fact.alpha: 1 - fact.beta.location: "{{ Naboo }}" - fact.beta.name: R2D2 - fact.msg: hello world + event.alpha: 1 + event.beta.location: "{{ Naboo }}" + event.beta.name: R2D2 + event.msg: hello world condition: AllCondition: - EqualsExpression: diff --git a/tests/e2e/test_actions.py b/tests/e2e/test_actions.py index b13b19fc..1aaa51fc 100644 --- a/tests/e2e/test_actions.py +++ b/tests/e2e/test_actions.py @@ -64,7 +64,7 @@ def test_actions_sanity(): 'ruleset': 'Test actions sanity', 'source_rule_name': 'debug', 'source_ruleset_name': 'Test actions sanity', - 'variables': {'event': {'action': 'debug'}, 'fact': {'action': 'debug'}}}""" # noqa: E501 + 'variables': {'event': {'action': 'debug'}}}""" # noqa: E501 assert event_debug_expected_output in result.stdout, "debug action failed" diff --git a/tests/rules/test_set_facts.yml b/tests/rules/test_set_facts.yml index b11e793b..08d2e5f4 100644 --- a/tests/rules/test_set_facts.yml +++ b/tests/rules/test_set_facts.yml @@ -23,8 +23,8 @@ name: playbooks/validate_args_playbook.yml extra_vars: my_vars: - fact.msg: hello world - fact.alpha: 1 - fact.beta.name: R2D2 - fact.beta.location: "{{ Naboo }}" + event.msg: hello world + event.alpha: 1 + event.beta.name: R2D2 + event.beta.location: "{{ Naboo }}" copy_files: True