ansible/event-driven-ansible

Webhook does not work with empty endpoint url

electronick opened this issue · 1 comments

Webhook listener does trigger only if endpoint url in not empty, i.e. it's not possible to configure listener on / url.

Example code:

- name: example webhook
  hosts: all
  sources:
    - ansible.eda.webhook:
        host: localhost
        port: 5000

  rules:
    - name: trigger when meta is defined
      condition: event.meta is defined
      action:
        debug:

Execute:

ansible-rulebook --rulebook example.yml -i hosts.yml --verbose

Example requests:

> curl -d "{\"data\": \"example\"}" http://localhost:5000/someurl 
webhook

Ansible-rulebook outputs:

INFO:aiohttp.access:127.0.0.1 [21/Nov/2022:17:39:41 +0000] "POST /someurl HTTP/1.1" 200 158 "-" "curl/7.79.1"
INFO:ansible_rulebook.rule_generator:calling trigger when meta is defined
INFO:ansible_rulebook.engine:call_action debug
INFO:ansible_rulebook.engine:substitute_variables [{}] [{'event': {'payload': {'data': 'example'}, 'meta': {'headers': {'Content_Type': 'application/x-www-form-urlencoded', 'Content_Length': '19', 'Accept': '*/*', 'Host': 'localhost:43005', 'User_Agent': 'curl/7.79.1'}, 'endpoint': 'someurl'}}, 'fact': {'payload': {'data': 'example'}, 'meta': {'headers': {'Content_Type': 'application/x-www-form-urlencoded', 'Content_Length': '19', 'Accept': '*/*', 'Host': 'localhost:5000', 'User_Agent': 'curl/7.79.1'}, 'endpoint': 'someurl'}}}]
INFO:ansible_rulebook.engine:action args: {}
============================================================================================================================================================================================================

When I make request to root url:

> curl -d "{\"data\": \"example\"}" http://localhost:5000/       
404: Not Found

Ansible-rulebook log outputs:

INFO:aiohttp.access:127.0.0.1 [21/Nov/2022:17:41:03 +0000] "POST / HTTP/1.1" 404 173 "-" "curl/7.79.1"

Just in case you need version information.

> ansible-rulebook --version
__version__ = '0.9.4'
ad5944ee-3782-48d6-8dae-1e924d00197f