Event driven automation with Ansible

Event driven automation with Ansible

What is this all about?

Just a few weeks ago we have had a new significant development in the Ansible space, it is the introduction of Event-Driven Ansible. It includes new tools which allows you to automatically trigger automation using events. This is what many of our customers have been doing with Ansible Automation Platform, Event-Driven Ansible both makes it easier to do and available to everyone, also those doing Ansible outside of Ansible Automation Platform and AWX.

Event-Driven Ansible is in developer preview, which means that we are collecting feedback. Get engaged and influence the development of this significant piece of technology. The upstream open source project lives here: https://github.com/ansible/event-driven-ansible

As Event-Driven Ansible matures, a qualified guess is that we can look forward for more event-driven features in Ansible Automation Platform as well ;)

I am myself very excited regarding this. Read on to learn more.

Review of what Event-Driven Ansible is

Let's dive into it all. First off, there's a compliment to the Ansible playbook, and it is called a rulebook. Rulebooks gets read by ansible-rulebook, just as playbooks are read by ansible-playbook.

Rulebooks are just as playbooks written in YAML but has some different structure. Let's have a look at one.

No alt text provided for this image

There are three parts of a rulebook:

  • Source?- The sources of our events come from source plugins. These plugins define where we are listening for events. There is support for a lot of different sources and more are planned to be added. View a list over current source plugins here: https://github.com/ansible/event-driven-ansible/tree/main/plugins/event_source. In our rulebook above, we use the url_check event source, which will produce two types of events, up and down.
  • Condition?- The conditional statements in the rulebook allow us to match criteria on which we want to have some kind of response to. Depending on source plugin, we have different conditions we can deal with. Many source plugins allows for an arbitrary number of different event types and therefor conditions we can define. The as the url_check plugin only provides two types of events, up and down, we can only have two conditions in our rulebook.
  • Action?- Lastly, the action is our response once the condition as been met from the event source. The action is the execution of a playbook. This can be done to trigger any automation of course, such as remediation, log a ticket for observation or generate other events which we would want to respond to. In our rulebook, we refer to two playbooks, site_up.yml and site_down.yml which we trigger depending on condition.

Here's the site_up.yml playbook:

No alt text provided for this image

Here's the site_down.yml playbook:

No alt text provided for this image

And here is what running the rulebook looks like:

ansible-rulebook --rules website-automation.yml -i inventory.yml --verbose

No alt text provided for this image

Try it out for yourself

You can access our free online lab to try out both the url_check example described above and another lab which uses the kafka source plugin here: https://www.ansible.com/products/ansible-training#event-driven-automation

If you want to try it out on your own systems, have a look at this repository, where I have put example rulebooks and playbooks: https://github.com/mglantz/event-driven-ansible-demo

To install ansible-rulebook, do this:

$ pip3 install ansible-rulebook
$ export JAVA_HOME=/usr/lib/jvm/java-17-openjdk        

Read more

This blog from Emily Bock is an excellent read: https://www.ansible.com/blog/introducing-event-driven-ansible

Mathias Gradin

Senior Advisor at Tolletaten

2 年

So what you are saying if we haven't yet started with ArgoCD, perhaps we should wait and investigate an other approach with ansible that we are more familiarly with?

回复
Roger Lindquist

CEO and Founder at Deslicer | Splunk & Automation Specialist | CISSP

2 年

Thanks for sharing this new project, it fits very well with next step self-tuning and self-healing automation. This will simplify a lot of complex automation triggers with the event listener! I’ll have a go with it and see what I can contribute with??

Edvin Norling

Platform engineer at Kognic

2 年

So do you will be running one Ansible rulebook instance per rulle that you want to setup? It seems a bit painful as scale... Or is the answer simple and if you want something central and at scale use Ansible Automation Platform? And i should see this more of an extra tool to be run on a specific server to help out with events only related to that server? I'm not in the Ansible space anymore but it looks very useful even though the scope is limited.

Magnus Glantz

Principal Specialist Solution Architect at Red Hat | author | spokesperson | linux | k8s | ansible | security

2 年

First pull request to Event Driven Ansible send. Improvements for the url_check source plugin :) Join in, it's a new project, so there's a lot to do. https://github.com/ansible/event-driven-ansible/pull/47

回复

要查看或添加评论,请登录

Magnus Glantz的更多文章

  • Public cloud exit - for dummies

    Public cloud exit - for dummies

    Welcome, by reading this you will better understand the challenges related to changing a public cloud provider for…

    17 条评论
  • We need to redefine what a broken system looks like

    We need to redefine what a broken system looks like

    We have a problem of a cultural kind, which will become painstakingly obvious when new security legislation such as…

    6 条评论
  • Logging AAP information on a target system

    Logging AAP information on a target system

    A customer of mine recently requested a new feature, which was added about a month ago. It adds a new configuration…

  • Protecting Ansible code and inventories using signing!

    Protecting Ansible code and inventories using signing!

    This is an article on how to use ansible-sign and Ansible Automation Platform to mitigate risk for supply chain attacks…

    13 条评论
  • YubiKey 2FA for Fedora 39

    YubiKey 2FA for Fedora 39

    This is a step-by-step guide on how to enable YubiKey 2FA for your Fedora 39 :) As preparations for a talk on Zero…

    4 条评论
  • DALL-E: Make it more open source!

    DALL-E: Make it more open source!

    It's a popular trend, so let's give it a try. Let's ask DALL-E to make something more and more and more open source…

    9 条评论
  • Analysis: Generative AI and automation: Part 1

    Analysis: Generative AI and automation: Part 1

    Hello there, My social media is getting filled to the brim with influencers which are letting me know that some new AI…

    7 条评论
  • The secret behind Fedora, CentOS and RHEL

    The secret behind Fedora, CentOS and RHEL

    I hope you slept well the past week. I was kept awake by constant discussions and thoughts ;) In an attempt to answer…

    62 条评论
  • The problem with Rocky Linux and free beer

    The problem with Rocky Linux and free beer

    Recent changes to how Red Hat publishes the source code for Red Hat Enterprise Linux has raised discussions about Red…

    299 条评论
  • Open Source and the SolarWinds hack

    Open Source and the SolarWinds hack

    By now, I'm guessing that you may have heard about the SolarWinds hack, often referred to as SunBurst. An assumed…

    17 条评论

社区洞察

其他会员也浏览了