ansible / ansible-rulebook

Apache License 2.0
196 stars 76 forks source link

feat: option to skip including events into extra_vars #716

Closed mkanoor closed 2 months ago

mkanoor commented 2 months ago

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

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

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
sonarcloud[bot] commented 2 months ago

Quality Gate Passed Quality Gate passed

Issues
0 New issues
0 Accepted issues

Measures
0 Security Hotspots
0.0% Coverage on New Code
2.8% Duplication on New Code

See analysis details on SonarCloud

mkanoor commented 2 months ago

Docs needs to be updated too. Otherwise LGTM

Updated