DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Please enter at least three characters to search
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Last call! Secure your stack and shape the future! Help dev teams across the globe navigate their software supply chain security challenges.

Modernize your data layer. Learn how to design cloud-native database architectures to meet the evolving demands of AI and GenAI workloads.

Releasing software shouldn't be stressful or risky. Learn how to leverage progressive delivery techniques to ensure safer deployments.

Avoid machine learning mistakes and boost model performance! Discover key ML patterns, anti-patterns, data strategies, and more.

Related

  • How to Monitor a Folder Using Event-Driven Ansible
  • Ansible Beyond Automation
  • Event-Driven Architectures: Designing Scalable and Resilient Cloud Solutions
  • Streamlining Event Data in Event-Driven Ansible

Trending

  • Evolution of Cloud Services for MCP/A2A Protocols in AI Agents
  • It’s Not About Control — It’s About Collaboration Between Architecture and Security
  • Issue and Present Verifiable Credentials With Spring Boot and Android
  • How to Practice TDD With Kotlin
  1. DZone
  2. Testing, Deployment, and Maintenance
  3. DevOps and CI/CD
  4. Simulating Events in Ansible EDA: A Practical Use Case of ansible.eda.generic

Simulating Events in Ansible EDA: A Practical Use Case of ansible.eda.generic

Learn how to include payloads directly within an Ansible EDA rulebook, as well as how to read payloads from an external file to use that data in rule conditions.

By 
Binoj Melath Nalinakshan Nair user avatar
Binoj Melath Nalinakshan Nair
DZone Core CORE ·
Apr. 09, 25 · Tutorial
Likes (7)
Comment
Save
Tweet
Share
6.2K Views

Join the DZone community and get the full member experience.

Join For Free

When developing an Event-Driven Ansible rulebook to automate tasks like handling a server outage or responding to a failed CI/CD job, testing the logic can be tricky if we don’t have a live system constantly generating events. That’s where the ansible.eda.generic source plugin comes in handy. It allows us to define mock events and inject them directly into the EDA workflow. This makes it easy to simulate real-time scenarios, test the rule conditions, and ensure the playbooks run as expected in a safe and controlled environment. 

In this article, I’ll walk you through how to include payloads directly within an Ansible EDA rulebook, as well as how to read payloads from an external file and use that data in rule conditions. I’ll also include some of the parameters like loop_count and loop_delay, which will help to control the number of times an event is triggered and the delay between each trigger. These features are especially helpful for simulating and managing event flow effectively during testing and development.

Working With Payloads in Ansible EDA Rulebooks

In this demo, we’ll look at two different ways to work with payloads in Ansible EDA rulebooks. The first rulebook, generic-payload.yml, includes the payload directly within the rulebook itself, making it simple and self-contained. The second, generic-payloadfile.yml, reads the payload from an external YAML file, allowing for better organization and reuse. The external payload is stored in events.yml, which makes it easy to manage test data separately. Both rulebooks trigger the same playbook, generic-handle.yml, which prints the payload details passed from the rulebook.

Examples of generic-payload.yml and generic-payloadfile.yml Rulebooks

Below are examples of the generic-payload.yml rulebook as well as the generic-payloadfile.yml rulebook. Screenshots of each outcome are also found below.

generic-payload.yml

YAML
 
- name: Generic Source Payload
  hosts: localhost
  sources:
    - ansible.eda.generic:
        payload:
         - { service_name: "webapp", status: "unhealthy", timestamp: "2025-03-30T12:00:00Z" }
        display: true
        loop_count: 3 
        loop_delay: 30 
        create_index: i
  rules:
    - name: Check if the service is unhealthy
      condition: event.status == "unhealthy"
      action:
        run_playbook:
          name: generic-handle.yml


generic-payloadfile.yml

YAML
 
- name: Generic Source Payload File
  hosts: localhost
  sources:
    - ansible.eda.generic:
        payload_file:
           "events.yml"
        display: true
        loop_count: 3 
        loop_delay: 30 
        create_index: i
  rules:
    - name: Check if the service is unhealthy
      condition: event.status == "unhealthy"
      action:
        run_playbook:
          name: generic-handle.yml


events.yml

YAML
 
  service_name: "webapp"
  status: "unhealthy"
  timestamp: "2025-03-30T12:00:00Z"


generic-handle.yml

YAML
 
- name: Handle Unhealthy Service Event
  hosts: localhost
  gather_facts: false
  tasks:
    - name: Print service issue
      debug:
        msg: >
          Detected that '{{ ansible_eda.event.service_name }}' is '{{ ansible_eda.event.status }}' at '{{ ansible_eda.event.timestamp }}', current system timestp '{{ now(fmt='%Y-%m-%d %H:%M:%S') }}'


Output Screenshot From thegeneric-payload.yml Execution

Below you can find the resulting screenshot from leveraging the generic-payload.yml execution:


This is a screenshot that contains the output of the generic-payload.yml execution.


Output screenshot from generic-payloadfile.yml execution

Conversely, you can now see the output from the generic-payloadfile.yml execution. 

This is a screenshot that contains the outputs of the generic-payloadfile.yml execution.


Conclusion

The ansible.eda.generic module is a valuable tool for developing and testing event-driven automation workflows in Ansible EDA. It enables the simulation of events through static payloads, allowing for easy validation of rule conditions and playbook behavior without needing live external systems. This approach is particularly useful during the development phase, where generating real-time events can be difficult. Leveraging the ansible.eda.generic plugin, we can design, test, and fine-tune the automation logic before integrating it with actual event sources.

Note: The views expressed in this article are my own and do not necessarily reflect the views of my employer.

YAML Ansible (software) Event-driven architecture

Opinions expressed by DZone contributors are their own.

Related

  • How to Monitor a Folder Using Event-Driven Ansible
  • Ansible Beyond Automation
  • Event-Driven Architectures: Designing Scalable and Resilient Cloud Solutions
  • Streamlining Event Data in Event-Driven Ansible

Partner Resources

×

Comments
Oops! Something Went Wrong

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends:

Likes
There are no likes...yet! 👀
Be the first to like this post!
It looks like you're not logged in.
Sign in to see who liked this post!