Este conteúdo não está disponível no idioma selecionado.
Chapter 7. Rulebook activations
A rulebook is a set of conditional rules that Event-Driven Ansible uses to perform IT actions in an event-driven automation model. Rulebooks are the means by which users tell Event-Driven Ansible which source to check for an event and when that event occurs what to do when certain conditions are met.
A rulebook specifies actions to be performed when a rule is triggered. A rule gets triggered when the events match the conditions for the rules. The following actions are currently supported:
-
run_playbook
(only supported with ansible-rulebook CLI) -
run_module
-
run_job_template
-
run_workflow_template
-
set_fact
-
post_event
-
retract_fact
-
print_event
-
shutdown
-
debug
-
none
To view further details, see Actions.
A rulebook activation is a process running in the background defined by a decision environment executing a specific rulebook. You can set up your rulebook activation by following Setting up a rulebook activation.
Red Hat does not recommend the use of a non-supported source plugin with 1 postgres database. This can pose a potential risk to your use of Ansible Automation Platform.
To meet high availability demands, Event-Driven Ansible controller shares centralized Redis (REmote DIctionary Server) with the Ansible Automation Platform UI. When Redis is unavailable, the following functions will not be available:
-
Creating an activation, if
is_enabled
is True - Deleting an activation
- Enabling an activation, if not already enabled
- Disabling an activation, if not already disabled
- Restarting an activation
7.1. Supported event sources Copiar o linkLink copiado para a área de transferência!
Event sources are a fundamental component of Event-Driven Ansible because they determine where a rulebook can receive events from. The effectiveness of a rulebook activation depends on selecting an event source that is compatible with your automation environment. Certain event sources are designed for use with the web-based Event-Driven Ansible controller, while others, due to their reliance on local host functionality, are exclusive to the ansible-rulebook
command-line interface (CLI). Understanding this distinction is crucial for successful rulebook activations.
The following list includes currently supported event sources for use with the web-based Event-Driven Ansible controller. You can decide which event sources provide the desired outcome for your rulebook activations.
-
alertmanager
-
aws_cloudtrail
-
aws_sqs_queue
-
azure_service_bus
-
kafka
-
pg_listener
-
webhook
7.2. Setting up a rulebook activation Copiar o linkLink copiado para a área de transferência!
You can create and configure a rulebook activation within the Ansible Automation Platform Dashboard. This process ensures effective management and deployment of your event-driven automation.
Prerequisites
- You are logged in to the Ansible Automation Platform Dashboard as a Content Consumer.
- You have set up a project.
- You have set up a decision environment.
Procedure
- Log in to Ansible Automation Platform.
-
Navigate to the
. - Click .
Insert the following:
- Name
- Insert the name.
- Description
- This field is optional.
- Organization
- Enter your organization name or select Default from the list.
- Project
- Projects are a logical collection of rulebooks. This field is optional.
- Rulebook
- Rulebooks are displayed according to the project selected.
- Credential
Select 0 or more credentials for this rulebook activation. This field is optional.
Note- The credentials that display in this field are customized based on your rulebook activation and only include the following credential types: Vault, Red Hat Ansible Automation Platform, or any custom credential types that you have created. For more information about credentials, see Credentials.
- If you plan to use a Red Hat Ansible Automation Platform credential, you can only select 1 Red Hat Ansible Automation Platform credential type for a rulebook activation.
- Decision environment
Decision environments are a container image to run Ansible rulebooks.
NoteIn Event-Driven Ansible controller, you cannot customize the pull policy of the decision environment. By default, it follows the behavior of the always policy. Every time an activation is started, the system tries to pull the most recent version of the image.
- Restart policy
This is the policy that determines how an activation should restart after the container process running the source plugin ends.
Policies:
- Always: This restarts the rulebook activation immediately, regardless of whether it ends successfully or not, and occurs no more than 5 times.
- Never: This never restarts a rulebook activation when the container process ends.
- On failure: This restarts the rulebook activation after 60 seconds by default, only when the container process fails, and occurs no more than 5 times.
- Log level
This field defines the severity and type of content in your logged events.
Levels:
- Error: Logs that contain error messages that are displayed in the History tab of an activation.
- Info: Logs that contain useful information about rulebook activations, such as a success or failure, triggered action names and their related action events, and errors.
- Debug: Logs that contain information that is only useful during the debug phase and might be of little value during production. This log level includes both error and log level data.
- Service name
- This defines a service name for Kubernetes to configure inbound connections if the activation exposes a port. This field is optional.
- Rulebook activation enabled?
- This automatically enables the rulebook activation to run.
- Variables
The variables for the rulebook are in a JSON or YAML format. The content would be equivalent to the file passed through the
--vars
flag of ansible-rulebook command.NoteIn the context of automation controller and Event-Driven Ansible controller, you can use both
extra_vars
and credentials to store a variety of information. However, credentials are the preferred method of storing sensitive information such as passwords or API keys because they offer better security and centralized management, whereasextra_vars
are more suitable for passing dynamic, non-sensitive data.- Options
- Check the Skip audit events option if you do not want to see your events in the Rule Audit.
- Click .
Results
Your rulebook activation is now created and can be managed on the Rulebook Activations page.
After saving the new rulebook activation, the rulebook activation’s details page is displayed, with either a Pending, Running, or Failed status. From there or the Rulebook Activations list view, you can restart or delete it.
Occasionally, when a source plugin shuts down, it causes a rulebook to exit gracefully after a certain amount of time. When a rulebook activation shuts down, any tasks that are waiting to be performed will be canceled, and an info level message is sent to the activation log. For more information, see Rulebooks.
7.3. Rulebook activation list view Copiar o linkLink copiado para a área de transferência!
On the Rulebook Activations page, you can view the rulebook activations that you have created along with the Status, Number of rules with the rulebook, the Fire count, and Restart count.
If the Status is Running, it means that the rulebook activation is running in the background and executing the required actions according to the rules declared in the rulebook.
You can view more details by selecting the activation from the Rulebook Activations list view.
For all activations that have run, you can view the Details and History tabs to get more information about what happened.
7.3.1. Viewing activation output Copiar o linkLink copiado para a área de transferência!
You can view the output of the activations in the History tab.
Procedure
- Select the History tab to access the list of all the activation instances. An activation instance represents a single execution of the activation.
- Then select the activation instance you want to view. The Output for the activation instance is displayed.
Next steps
To view events that came in and triggered an action, navigate to
7.4. Enabling and disabling rulebook activations Copiar o linkLink copiado para a área de transferência!
You can enable or disable rulebook activations to control when they run. Disabling an activation is useful for troubleshooting or to temporarily halt automation without deleting the configuration.
Procedure
- Select the switch on the row level to enable or disable your chosen rulebook.
- In the window, select .
- Select .
7.5. Restarting rulebook activations Copiar o linkLink copiado para a área de transferência!
You can restart a rulebook activation to quickly re-engage its automation, which is useful after making updates or to recover from an error.
You can only restart a rulebook activation if it is currently enabled and the restart policy was set to Always when it was created.
Procedure
- Select the ⋮ next to Rulebook Activation enabled/disabled toggle. icon
- Select .
- In the window, select .
- Select .
7.6. Editing a rulebook activation Copiar o linkLink copiado para a área de transferência!
You can edit a rulebook activation after you have created or run it to correct input for fields (log levels, Restart policy, turn auditing off or on, and the like) or help mitigate issues caused by failure.
Procedure
On the Rulebook Activations page, next to the activation you want to edit, toggle the
button to the off position first to disable the activation.The Disable rulebook activations message is displayed asking you to confirm that you want to disable the activation.
- Select the Yes, I confirm that I want to disable these <1> rulebook activations checkbox and click .
Next to the rulebook activation, click the Edit icon. This takes you to the Edit form.
NoteYou can also access the Edit feature by clicking the rulebook activation on the Rulebook Activations page, toggling the button to the off position, confirming that you want to disable the activation, and clicking the button on the top right of the page to access the Edit form.
Edit the desired fields.
NoteIf you prefer to run your activation immediately, you can toggle the
button to the on position, and then save your changes.- Click .
Results
This takes you back to the Rulebook Activations page.
7.7. Duplicating a rulebook activation Copiar o linkLink copiado para a área de transferência!
When setting up a new rulebook activation with field inputs that are similar to one of your existing rulebook activations, you can use the Duplicate rulebook activation feature instead of manually entering input into each field. While setting up rulebook activations can be a lengthy process, the ability to duplicate the required fields from an existing activation saves time and, in some cases, reduces the possibility of human error.
Procedure
On the Rulebook Activations page, click the More Actions icon ⋮ on the row of the activation you want to duplicate. The More Actions list is displayed with three options:
- Restart rulebook activation
- Duplicate rulebook activation
- Delete rulebook activation
Select
.A message is displayed: "<Name of rulebook activation 1> duplicated." Initially, the newly duplicated activation is displayed as disabled on the Rulebook Activations page with the same name as the original activation followed by a time stamp in 24-hour format (for example, <Name of rulebook activation 1> @ 18:43:27).
ImportantThe original rulebook activation continues to run after you have duplicated it. If you try to enable the duplicated activation without editing the fields (including the Name field) to distinguish it from the original, a message is displayed reminding you that the rulebook activation was duplicated from an original, and enabling it might fail or result in duplicate jobs and other complications.
Before you run the duplicated rulebook activation, edit the fields by completing the following:
- Next to the duplicated rulebook activation, click the Edit icon. This takes you to the Edit form.
Edit the desired fields.
NoteEnsure that you have given your newly duplicated activation a meaningful Name that distinguishes it from the original activation.
- Toggle the button to the on position.
- After confirming all of your edits are complete, click .
Results
This initiates the rulebook activation, and if it runs successfully, the status changes to Running or Completed.
7.8. Deleting rulebook activations Copiar o linkLink copiado para a área de transferência!
You can delete rulebook activations to permanently remove them when they are no longer needed.
Procedure
- Select the ⋮ next to the Rulebook Activation enabled/disabled toggle. icon
- Select .
- In the window, select .
- Select .
7.9. Activating webhook rulebooks Copiar o linkLink copiado para a área de transferência!
In Openshift environments, you can allow webhooks to reach an activation-job-pod over a given port by creating a route that exposes that rulebook activation’s Kubernetes service.
Prerequisites
- You have created a rulebook activation.
The following is an example of rulebook with a given webhook:
Procedure
Create a Route (on OpenShift Container Platform) to expose the service. The following is an example Route for an ansible-rulebook source that expects POST’s on port 5000 on the decision environment pod:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow When you create the Route, test it with a Post to the Route URL:
NoteYou do not need the port as it is specified on the Route (targetPort).
curl -H "Content-Type: application/json" -X POST test-sync-bug-dynatrace.apps.aap-dt.ocp4.testing.ansible.com -d '{}'
curl -H "Content-Type: application/json" -X POST test-sync-bug-dynatrace.apps.aap-dt.ocp4.testing.ansible.com -d '{}'
Copy to Clipboard Copied! Toggle word wrap Toggle overflow
7.10. Testing with Kubernetes Copiar o linkLink copiado para a área de transferência!
With Kubernetes you can create an Ingress, or expose the port, but not for production.
Procedure
Run the following command to expose the port on the cluster for a given service:
kubectl port-forward svc/<ACTIVATION_SVC_NAME> 5000:5000
kubectl port-forward svc/<ACTIVATION_SVC_NAME> 5000:5000
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Make the HTTP requests against the
localhost:5000
to trigger the rulebook:curl -H "Content-Type: application/json" -X POST test-sync-bug-dynatrace.apps.aap-dt.ocp4.testing.ansible.com -d '{}'
curl -H "Content-Type: application/json" -X POST test-sync-bug-dynatrace.apps.aap-dt.ocp4.testing.ansible.com -d '{}'
Copy to Clipboard Copied! Toggle word wrap Toggle overflow