Skip to main content

ansible-events

https://img.shields.io/pypi/v/ansible_events.svg https://img.shields.io/travis/benthomasson/ansible_events.svg Documentation Status

Event driven automation for Ansible.

The real world is fully of events that change the state of our software and systems. Our automation needs to be able to react to those events. Ansible-events is a command line tool that allows you to recognize which events that you care about and react accordingly by running a playbook or other actions.

Let’s get started with a simple hello world example to familiarize ourselves with the concepts:

---
- name: Hello Events
  hosts: localhost
  sources:
    - benthomasson.eda.range:
        limit: 5
  rules:
    - name: Say Hello
      condition: event.i == 1
      action:
        run_playbook:
          name: benthomasson.eda.hello
...

Events come from a event source and then are checked against rules to determine if an action should be taken. If the condition of a rule matches the event it will run the action for that rule.

In this example the event source is the Python range function. It produces events that count from i=0 to i=<limit>.

When i is equal to 1 the condition for the the Say Hello rule matches and it runs a playbook.

Normally events would come from monitoring and alerting systems or other software. The following is a more complete example that accepts alerts from Alertmanager:

---
- name: Automatic Remediation of a webserver
  hosts: all
  sources:
    - name: listen for alerts
      benthomasson.eda.alertmanager:
        host: 0.0.0.0
        port: 8000
  rules:
    - name: restart web server
      condition: event.alert.labels.job == "fastapi" and event.alert.status == "firing"
      action:
        run_playbook:
          name: benthomasson.eda.start_app
...

This example sets up a webhook to receive events from alertmanager and then matches events where the fastapi job alert has a staus of firing. This runs a playbook that will remediate the issue.

Features

  • Conditionally launch playbooks based on rules that match events in event streams.

Examples

Rules are organized into rulesets using a syntax that is similar to ansible-playbooks:

---
- name: Hello Events
  hosts: localhost
  sources:
    - benthomasson.eda.range:
        limit: 5
  rules:
    - name: Say Hello
      condition: event.i == 1
      action:
        run_playbook:
          name: benthomasson.eda.hello
...

Each ruleset defines: a set of hosts to pass to the playbook, a set of event sources, and a set of rules. The set of hosts is the normal hosts pattern from ansible playbooks. The event sources are a new type of plugin that subscribe to events from event streams. The rules have conditions that match values in the events and actions that can run playbooks, assert facts, retract facts, and print information to the console.

Let’s look closer at the event source:

- benthomasson.eda.range:
    limit: 5

This section of YAML defines that an event source plugin from the benthomasson.eda should be loaded and given the arguments: limit=5. This source will generate a range of numbers from zero to 4 and then exit.

The rules YAML structure looks like the following:

- name: Say Hello
  condition: event.i == 1
  action:
    run_playbook:
      name: benthomasson.eda.hello

This block of YAML defines a rule with name “Say Hello”, a condition that matches when an event has an value “i” that is equal to 1, and an action that runs a playbook inside the collection benthomasson.eda.

How to install

Via PyPi:

pip install ansible-events

Via Docker:

docker build -t ansible-events .

Usage

ansible-events --help

Credits

This package was created with Cookiecutter and the audreyr/cookiecutter-pypackage project template.

History

0.1.0 (2022-02-16)

  • First release on PyPI.

Metadata

Release files for ansible-events 0.7.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for ansible-events 0.7.0
File Size Uploaded Provenance
ansible_events-0.7.0.tar.gz 96.6 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for ansible-events 0.7.0
File Interpreter ABI Platform
ansible_events-0.7.0-py3-none-any.whl Python 3 none any Details

Total release size: 123.7 kB

Release files / ansible_events-0.7.0.tar.gz

Download URL ansible_events-0.7.0.tar.gz
Size 96.6 kB
Tags Source
SHA-256 checksum
How to use checksums
f3b63af14cdefac524a40e008551d50023bec3731ca872d3ae250b1850a73542
BLAKE2b-256 checksum
How to use checksums
605dc5d01d27ce9649b5082a03a9c0f17cccf02dc245bdcee88bbf773b9e98aa
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.14.0 pkginfo/1.8.2 requests/2.27.1 setuptools/57.0.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.13

Release files / ansible_events-0.7.0-py3-none-any.whl

Download URL ansible_events-0.7.0-py3-none-any.whl
Size 27.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
32d6a1d5c338bc967c244f86c5b5b9db9e0c177726699d9aed927bc5807e32d8
BLAKE2b-256 checksum
How to use checksums
305e242474f12470bc1542489ecf039742db1922642f53d5a7fe027331174b41
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.14.0 pkginfo/1.8.2 requests/2.27.1 setuptools/57.0.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.13

Security for ansible-events 0.7.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page