Rulebooks
Rulesets
A ruleset has the following properties:
Name |
Description |
Required |
---|---|---|
name |
The name to identify the ruleset. Each ruleset must have an unique name across the rulebook. |
Yes |
sources |
The list of one or more sources that will generate events for ansible-rulebook. See Event Source Plugins |
Yes |
rules |
The list of one or more rule. See Rules |
Yes |
hosts |
Similar to hosts in an Ansible playbook |
Yes |
gather_facts |
Collect artifacts from hosts at startup to be used in rules (default: false) |
No |
default_events_ttl |
time to keep the partially matched events around (default: 2 hours) |
No |
execution_strategy |
Action execution, sequential or parallel (default: sequential). For sequential strategy we wait for the each action to finish before firing of the next action. |
No |
- name: Example
hosts: all
gather_facts: true
sources:
- name: range
ansible.eda.range:
limit: 5
rules:
- name: r1
condition: event.i == 1
action:
debug:
- name: "Host specific rule"
condition:
all:
- fact.ansible_os_family == "linux"
- fact.meta.hosts == "my-host"
- event.i == 4
action:
debug:
Including multiple sources
In a rulebook you can configure one or more sources, each emitting events in different format.
Example
sources:
- ansible.eda.range:
limit: 6
- ansible.eda.webhook:
port: 5000
The condition can match events from either source
rules:
- name:
condition: event.i == 2
action:
debug:
- name:
condition: event.payload.status == "OK"
action:
debug:
To avoid name conflicts the source data structure can use nested keys.
Notes:
If any source terminates, it shuts down the whole engine. All events from other sources may be lost.
Distributing rulebooks
The recommended method for distributing rulebooks is through a collection. In this case
the rulebook file should be placed under extensions/eda/rulebooks
folder
and referred to by FQCN in the command line argument. Eda-server project will honor this path
for the projects even if the repository is not real collection.