Chapter 2. Ansible rulebooks
Event-Driven Ansible controller provides the interface in which Event-Driven Ansible automation performs. Ansible rulebook provides the framework for Event-Driven Ansible automation. Ansible rulebook is essentially a collection of rulesets, which in turn, consists of one or more sources, rules, and conditions.
2.1. Decision Environments
Event-Driven Ansible includes, by default, an ansible.eda collection, which contains sample sources, event filters and rulebooks. All the collections, ansible rulebooks and their dependencies use a Decision Environment, which is an image that can be run on either Podman or Kubernetes.
In Decision Environments, sources, which are typically Python code, are distributed through ansible-collections. They inject external events into a rulebook for processing. The rulebook consists of the following:
- The python interpreter
- Java Runtime Environment for Drools rule engine
- ansible-rulebook python package
- ansible.eda collection
You can use the base Decision Environment and build your own customized Decision Environments with additional collections and collection dependencies. You can build a Decision Environment using a Dockerfile or optionally you can deploy your CA certificate into the image.
2.2. Rulebook actions
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_job_template
-
run_playbook
(only supported with ansible-rulebook CLI) -
debug
-
print_event
-
set_fact
-
post_event
-
retract_fact
-
shutdown
Additional resources
- For more information on using rulebooks, see the Event-Driven Ansible controller User’s Guide.
- For more detailed information on Ansible rulebooks, see the section on Rulebooks in the Ansible Rulebook documentation.