ansible/ansible-rulebook

The event that triggered the playbook is not passed to the playbook

pywang0122 opened this issue · 2 comments

Please confirm the following

  • I agree to follow this project's code of conduct.
  • I have checked the current issues for duplicates.
  • I understand that ansible-rulebook is open source software provided for free and that I might not receive a timely response.

Bug Summary

Hello. I have a weird issue recently. The playbook invoked by the rulebook doesn't know about the event that triggered it:
TASK [debug] *******************************************************************
fatal: [localhost]: FAILED! => {"msg": "The task includes an option with an undefined variable. The error was: 'event' is undefined. 'event' is undefined\n\nThe error appears to be in '/tmp/run_playbookj7pb1b06/project/say-what.yml': line 7, column 7, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line
appears to be:\n\n tasks:\n - debug:\n ^ here\n"}
The code with issue is:

Environment

Redhat8

Steps to reproduce

Use https://github.com/ansible/ansible-rulebook/blob/main/Dockerfile to build a images, deploy and run it, have the rulebook listen to port 5010. send a webhook message:
curl -H 'Content-Type: application/json' -d "{"message": "Ansible is super cool", "sender": "deployer node"}" http://localhost:5010/endpoint

Actual results

Playbook fails with:
TASK [debug] *******************************************************************
fatal: [localhost]: FAILED! => {"msg": "The task includes an option with an undefined variable. The error was: 'event' is undefined. 'event' is undefined\n\nThe error appears to be in '/tmp/run_playbookj7pb1b06/project/say-what.yml': line 7, column 7, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line
appears to be:\n\n tasks:\n - debug:\n ^ here\n"}
The code with issue is:

  • debug:
    msg: "Thank you!!!! {{ event.payload.sender }}!"

Expected results

playbook should run successfully and display: Thank you!!!! deployer node

Additional information

No response

Hi @pywang0122, you need to prepend the variable in your playbook with ansible_eda. For information in the documentation here: https://ansible-rulebook.readthedocs.io/en/stable/variables.html#providing-extra-vars-to-actions

Hi @ttuffin, thank you so much! It is working now.