# Testing Rulebooks, how do you folks do it?

**URL:** <https://forum.ansible.com/t/testing-rulebooks-how-do-you-folks-do-it/4484>\
**Category:** Get Help\
**Tags:** eda-server\
**Created:** [March 20, 2024, 4:35pm UTC](https://forum.ansible.com/t/testing-rulebooks-how-do-you-folks-do-it/4484 "2024-03-20T16:35:36Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![skeer](https://avatars.discourse-cdn.com/v4/letter/s/7ea924/32.png) [@skeer](https://forum.ansible.com/u/skeer)\
**Post date:** [March 20, 2024, 4:35pm UTC](https://forum.ansible.com/t/testing-rulebooks-how-do-you-folks-do-it/4484/1 "2024-03-20T16:35:36Z")

</div>

Just wondering, I can’t find really anything meaty on how to test rulebooks using ansible-rulebook.  
When developing new rulebooks, how do you experienced folks test them?

---

<div class="post-metadata">

**Author:** ![Alex-Izquierdo](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/alex-izquierdo/32/679_2.png) [@Alex-Izquierdo](https://forum.ansible.com/u/Alex-Izquierdo)\
**Post date:** [March 20, 2024, 5:40pm UTC](https://forum.ansible.com/t/testing-rulebooks-how-do-you-folks-do-it/4484/2 "2024-03-20T17:40:46Z")

</div>

Hello @skeer  
I think having a chapter in the documentation for this purpose is a good idea. For now I can share some tips and tricks that may be useful.

Usually, when you develop a rulebook, one of the things that you want to know is how looks the event. In that case, the flag --print-events allows you to print in the stdout all the events received.

As alternative to “–print-events” you can always start with a basic condition that will match any event. The debug action is your best friend.

```auto
condition: true
action:
  debug: "{{ event }}"

```

If its complicated to produce/get real events from your source but you know how they looks like, you can use the [“generic” plugin in ansible.eda](https://github.com/ansible/event-driven-ansible/blob/main/extensions/eda/plugins/event_source/generic.py) collection that allows you to define your custom event.

Also you have the flag “–hot-reload” which allows you run your ansible-rulebook process only one time and modify you rulebook.

Writing conditions might be a challenge if your logic or the event is complex. Always have [the documentation at hand](https://ansible.readthedocs.io/projects/rulebook/en/latest/conditions.html) to see all the operators and functionalities that ansible-rulebook provides.

Finally, as a trick, I did some experiments with prompt engineering in LLM models, providing the documentation and some examples as prompt, and using the model to describe a condition and a sample payload to get the condition.

---

<div class="post-metadata">

**Author:** ![Alex-Izquierdo](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/alex-izquierdo/32/679_2.png) [@Alex-Izquierdo](https://forum.ansible.com/u/Alex-Izquierdo)\
**Post date:** [March 20, 2024, 5:41pm UTC](https://forum.ansible.com/t/testing-rulebooks-how-do-you-folks-do-it/4484/3 "2024-03-20T17:41:35Z")

</div>

Tools like [https://jsonpathfinder.com/](https://jsonpathfinder.com/) can help you to navigate and find the path for some value in big and complex payloads.

I could not add a third link in my previous message :s

---

<div class="post-metadata">

**Author:** ![skeer](https://avatars.discourse-cdn.com/v4/letter/s/7ea924/32.png) [@skeer](https://forum.ansible.com/u/skeer)\
**Post date:** [March 20, 2024, 6:52pm UTC](https://forum.ansible.com/t/testing-rulebooks-how-do-you-folks-do-it/4484/4 "2024-03-20T18:52:17Z")

</div>

Thank you for this and yes I’d agree wholeheartedly about the doc addition. Every Tom, Dick, and Harry out there has websites, blog/reddit posts and YT videos on creating Playbooks, Roles and Collections. There’s almost zilch for rulebooks though, and since an RB will almost always have a tie back to an Ansible controller, it makes a testing scenario that much more complicated.  
I appreciate your info!

---

<div class="post-metadata">

**Author:** ![carlyle705](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/carlyle705/32/5552_2.png) [@carlyle705](https://forum.ansible.com/u/carlyle705)\
**Post date:** [November 25, 2024, 6:07pm UTC](https://forum.ansible.com/t/testing-rulebooks-how-do-you-folks-do-it/4484/5 "2024-11-25T18:07:36Z")

</div>

Hello @Alex-Izquierdo Could you please share some ideas on how to write condition statement to match a variable from the header of a webhook? For example, if I want to test the value of a key “os” and see if it is “linux”, I wrote:  
`condition: event.meta.headers.os == "linux"`  
But it won’t trigger the template I defined. Match variables from the payload is working:  
`condition: event.payload.event_type == 'deployed'`

Thanks.
