-
Notifications
You must be signed in to change notification settings - Fork 77
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: option to skip including events into extra_vars (#716)
When we unconditionally send event data to the controller for a workflow template the launch of the workflow template fails. With this option in a rulebook the user can prevent event data from being sent by setting - include_events: false The default value is true so existing rulebooks will keep sending events to controller. Fixes #622 https://issues.redhat.com/browse/AAP-13456 Root Cause Analysis: In the Controller if you are running a workflow template you cannot send event data to it unconditionally like we can do with job template. We get an error from Controller **Check the Prompt on Launch setting on the Workflow Job Template to include Extra Variables.** If a survey spec is involved then there are more constraints if there are certain parameters that are marked as required in the survey spec. So we get 2 distinct items - Prompt on Launch for Extra Variables - Survey Spec The following use cases are supported for workflow job template with and without survey spec. The use cases are based on a rulebook that looks like the following with the action being updated for every case. ``` --- - name: Test run job templates hosts: all sources: - ansible.eda.generic: payload: - name: Fred age: 25 rules: - name: "Run job template" condition: event.age == 25 action: run_workflow_template: name: workflow_mk organization: Default ``` ### **Case 1:** If your Workflow Template doesn't support Prompt on Launch for Extra Vars and a Survey Spec is not enabled ``` run_workflow_template: name: workflow_mk include_events: false organization: Default ``` ### **Case 2:** If your Workflow Template supports Prompt on Launch for Extra Vars and a Survey Spec is not enabled ``` run_workflow_template: name: workflow_mk organization: Default job_args: extra_vars: name: "{{ event.name }}" ``` The payload sent to Controller ``` name: Fred ansible_eda: ruleset: Test run job templates rule: Run job template event: meta: source: name: ansible.eda.generic type: ansible.eda.generic received_at: '2024-09-26T05:29:10.983346Z' uuid: 9570c7f8-9bc9-438f-9199-803707e31ccf name: Fred age: 25 ``` ### **Case 3:** If your Workflow Template doesn't support Prompt on Launch for Extra Vars and a Survey Spec is enabled ``` run_workflow_template: name: workflow_mk include_events: false organization: Default job_args: extra_vars: name: "{{ event.name }}" ``` The payload sent to Controller ``` name: Fred ``` ### **Case 4:** If your Workflow Template supports Prompt on Launch for Extra Vars and a Survey Spec is enabled ``` action: run_workflow_template: name: workflow_mk organization: Default job_args: extra_vars: name: "{{ event.name }}" ``` The payload sent to Controller ``` name: Fred ansible_eda: ruleset: Test run job templates rule: Run job template event: meta: source: name: ansible.eda.generic type: ansible.eda.generic received_at: '2024-09-26T07:26:42.160723Z' uuid: 46169e51-ba6f-4a55-963b-b626fff7cfdc name: Fred age: 25 ``` ### **Case 5:** Survey Spec has a required parameter and its not provided ``` action: run_workflow_template: name: workflow_mk organization: Default ``` Missing args 2024-09-26 12:59:03,738 - ansible_rulebook.job_template_runner - ERROR - Error {'variables_needed_to_start': ["'name' value missing"]} ### **Case 6:** Survey Spec has no required parameter and its not provided ``` action: run_workflow_template: name: workflow_mk organization: Default ``` The Default Value is provided by the Survey Spec and it works ``` name: fred ansible_eda: ruleset: Test run job templates rule: Run job template event: meta: source: name: ansible.eda.generic type: ansible.eda.generic received_at: '2024-09-26T07:55:15.320036Z' uuid: 68a6c25d-dcf5-4a1c-8eb2-7432376d2d88 name: Fred age: 25 ```
- Loading branch information
1 parent
dc0da3a
commit 819f0dc
Showing
14 changed files
with
248 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# Complete documentation with many more options at: | ||
# https://docs.sonarqube.org/latest/analysis/analysis-parameters/ | ||
|
||
## The unique project identifier. This is mandatory. | ||
# Do not duplicate or reuse! | ||
# Available characters: [a-zA-Z0-9_:\.\-] | ||
# Must have least one non-digit. | ||
# Recommended format: <group>:<project> | ||
sonar.projectKey=ansible_ansible-rulebook | ||
|
||
sonar.organization=ansible | ||
|
||
# Customize what paths to scan. Default is . | ||
sonar.sources=. | ||
|
||
# Verbose name of project displayed in WUI. Default is set to the projectKey. This field is optional. | ||
sonar.projectName=ansible-rulebook | ||
|
||
sonar.issue.ignore.multicriteria=e1 | ||
# Ignore "should be a variable" | ||
#sonar.issue.ignore.multicriteria.e1.ruleKey=python:S1192 | ||
sonar.issue.ignore.multicriteria.e1.resourceKey=**/action/* | ||
|
||
# Only scan with python3 | ||
sonar.python.version=3.9,3.10,3.11,3.12 | ||
|
||
# Ignore code dupe for premature code reuse recommened in PR | ||
# https://github.com/ansible/ansible-rulebook/pull/537#issuecomment-1598883529 | ||
sonar.cpd.exclusions=**/action/* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
--- | ||
- name: Test run job templates without event payload | ||
hosts: all | ||
sources: | ||
- ansible.eda.generic: | ||
payload: | ||
- age: 55 | ||
name: Fred | ||
zip: 12345 | ||
rules: | ||
- name: "Run job template" | ||
condition: event.name == "Fred" | ||
action: | ||
run_job_template: | ||
name: Demo Job Template | ||
organization: Default | ||
include_events: false | ||
job_args: | ||
extra_vars: | ||
name: "{{ event.name }}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
--- | ||
- name: Test run workflow templates without event payload | ||
hosts: all | ||
sources: | ||
- ansible.eda.generic: | ||
payload: | ||
- age: 55 | ||
name: Fred | ||
zip: "12345" | ||
rules: | ||
- name: "Run workflow template" | ||
condition: event.name == "Fred" | ||
action: | ||
run_workflow_template: | ||
name: Demo Workflow Template | ||
organization: Default | ||
include_events: false | ||
job_args: | ||
extra_vars: | ||
name: "{{ event.name }}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
--- | ||
- name: Test run job templates with event payload | ||
hosts: all | ||
sources: | ||
- ansible.eda.generic: | ||
payload: | ||
- age: 55 | ||
name: Fred | ||
zip: 12345 | ||
rules: | ||
- name: "Run job template" | ||
condition: event.name == "Fred" | ||
action: | ||
run_job_template: | ||
name: Demo Job Template | ||
organization: Default | ||
job_args: | ||
extra_vars: | ||
name: "{{ event.name }}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
--- | ||
- name: Test run workflow templates with event payload | ||
hosts: all | ||
sources: | ||
- ansible.eda.generic: | ||
payload: | ||
- age: 55 | ||
name: Fred | ||
zip: "12345" | ||
rules: | ||
- name: "Run workflow template" | ||
condition: event.name == "Fred" | ||
action: | ||
run_workflow_template: | ||
name: Demo Workflow Template | ||
organization: Default | ||
job_args: | ||
extra_vars: | ||
name: "{{ event.name }}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
--- | ||
- name: Test run job templates with no args | ||
hosts: all | ||
sources: | ||
- ansible.eda.generic: | ||
payload: | ||
- age: 55 | ||
name: Fred | ||
zip: 12345 | ||
rules: | ||
- name: "Run job template" | ||
condition: event.name == "Fred" | ||
action: | ||
run_job_template: | ||
name: Demo Job Template | ||
organization: Default |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters