Automatic Healing with Ansible
...Or with Event Driven Ansible!
About Me
Sebastian Gumprich
T-Systems MMS GmbH
Lots of time
What is Event Driven Ansible?
> a new way to enhance and expand automation. It improves
IT speed and agility, while enabling consistency and
resilience.
IFTT for sysadmins
How does it work?
Playbooks + Rulebook =
Sources
Webhooks
Alertmanager
URLs
Files
more to come
Rules
What should happen when?
Conditions
Alerts from Alertmanager
Unreachable Website
Newly created files
Message in Webhook
Actions
run_playbook
run_module
set_fact
Rulebook
---
- name: Listen for events on a webhook
hosts: all
## Define our source for events
sources:
- ansible.eda.webhook:
host: 0.0.0.0
port: 5000
## Define the conditions we are looking for
rules:
- name: Say Hello
condition: event.payload.message == "Ansible is super cool"
## Define the action we should take should the condition be met
action:
run_playbook:
name: say-what.yml
Why?
Ansible is push-based
Event Driven Ansible is event-based
Helps to automatically fix and troubleshoot
problems
Installation
apt-get --assume-yes install build-essential maven openjdk-17-jdk python3-dev python3-pip
export JDK_HOME=/usr/lib/jvm/java-17-openjdk-amd64
export JAVA_HOME=$JDK_HOME
export PIP_NO_BINARY=jpy
export PATH=$PATH:~/.local/bin
pip3 install -U Jinja2
pip3 install ansible ansible-rulebook ansible-runner wheel
Add a Playbook and Inventory
playbook:
- hosts: localhost
connection: local
tasks:
- debug:
msg: "Thank you, my friend!"
inventory
localhost
Running it
> ansible-rulebook --rulebook webhook-rule.yml -i inventory.yml --verbose
INFO:ansible_rulebook.app:Starting sources
INFO:ansible_rulebook.app:Starting rules
INFO:ansible_rulebook.engine:run_ruleset
...
INFO:ansible_rulebook.engine:load source
INFO:ansible_rulebook.engine:load source filters
INFO:ansible_rulebook.engine:Calling main in ansible.eda.webhook
INFO:ansible_rulebook.engine:Waiting for event from Listen for events on a webhook
Using it
What I do
> curl -d "{"message": "Ansible is super cool"}" http://127.0.0.1:5000/endpoint
What Event Driven Ansible does
INFO:ansible_rulebook.engine:action args: {'name': 'say-what.yml'}
INFO:ansible_rulebook.builtin:running Ansible playbook: say-what.yml
INFO:ansible_rulebook.builtin:ruleset: Listen for events on a webhook, rule: Say Hello
INFO:ansible_rulebook.builtin:Calling Ansible runner
PLAY [say thanks] **************************************************************
TASK [Gathering Facts] *********************************************************
ok: [localhost]
TASK [debug] *******************************************************************
ok: [localhost] => {
"msg": "say what"
}
Dynamic loading of Playbooks (but not rulebooks)
Event Driven Ansible Server
Like AWX/Tower/whatever it's called now
Event Driven Ansible Server #2
Web-UI
REST-API
Is it production-ready?
In Early Development
Core functionality is there
Thanks!
Let's chat!

OSMC 2022 | IGNITE: Event Driven Ansible by Sebastian Gumprich

  • 1.
    Automatic Healing withAnsible ...Or with Event Driven Ansible!
  • 2.
  • 3.
    What is EventDriven Ansible? > a new way to enhance and expand automation. It improves IT speed and agility, while enabling consistency and resilience. IFTT for sysadmins
  • 4.
    How does itwork? Playbooks + Rulebook =
  • 5.
  • 6.
  • 7.
    Conditions Alerts from Alertmanager UnreachableWebsite Newly created files Message in Webhook
  • 8.
  • 9.
    Rulebook --- - name: Listenfor events on a webhook hosts: all ## Define our source for events sources: - ansible.eda.webhook: host: 0.0.0.0 port: 5000 ## Define the conditions we are looking for rules: - name: Say Hello condition: event.payload.message == "Ansible is super cool" ## Define the action we should take should the condition be met action: run_playbook: name: say-what.yml
  • 10.
    Why? Ansible is push-based EventDriven Ansible is event-based
  • 11.
    Helps to automaticallyfix and troubleshoot problems
  • 12.
    Installation apt-get --assume-yes installbuild-essential maven openjdk-17-jdk python3-dev python3-pip export JDK_HOME=/usr/lib/jvm/java-17-openjdk-amd64 export JAVA_HOME=$JDK_HOME export PIP_NO_BINARY=jpy export PATH=$PATH:~/.local/bin pip3 install -U Jinja2 pip3 install ansible ansible-rulebook ansible-runner wheel
  • 13.
    Add a Playbookand Inventory playbook: - hosts: localhost connection: local tasks: - debug: msg: "Thank you, my friend!" inventory localhost
  • 14.
    Running it > ansible-rulebook--rulebook webhook-rule.yml -i inventory.yml --verbose INFO:ansible_rulebook.app:Starting sources INFO:ansible_rulebook.app:Starting rules INFO:ansible_rulebook.engine:run_ruleset ... INFO:ansible_rulebook.engine:load source INFO:ansible_rulebook.engine:load source filters INFO:ansible_rulebook.engine:Calling main in ansible.eda.webhook INFO:ansible_rulebook.engine:Waiting for event from Listen for events on a webhook
  • 15.
    Using it What Ido > curl -d "{"message": "Ansible is super cool"}" http://127.0.0.1:5000/endpoint What Event Driven Ansible does INFO:ansible_rulebook.engine:action args: {'name': 'say-what.yml'} INFO:ansible_rulebook.builtin:running Ansible playbook: say-what.yml INFO:ansible_rulebook.builtin:ruleset: Listen for events on a webhook, rule: Say Hello INFO:ansible_rulebook.builtin:Calling Ansible runner PLAY [say thanks] ************************************************************** TASK [Gathering Facts] ********************************************************* ok: [localhost] TASK [debug] ******************************************************************* ok: [localhost] => { "msg": "say what" }
  • 16.
    Dynamic loading ofPlaybooks (but not rulebooks)
  • 17.
    Event Driven AnsibleServer Like AWX/Tower/whatever it's called now
  • 18.
    Event Driven AnsibleServer #2 Web-UI REST-API
  • 19.
    Is it production-ready? InEarly Development Core functionality is there
  • 20.