在事件驱动的 Ansible 中简化事件数据

  • Event-Driven Ansible (EDA): Event filters are crucial in EDA for preparing incoming data. Previously, the ansible.eda.dashes_to_underscores filter was explored.
  • Two more event filters: ansible.eda.json_filter and ansible.eda.normalize_keys give more control over incoming event data.

    • ansible.eda.json_filter: Allows picking and choosing keys to keep or drop from the payload, making automation run faster and reducing mistakes.
    • ansible.eda.normalize_keys: Addresses inconsistent key formats by converting keys with non-alphanumeric characters into a standardized format using underscores.
  • Testing the filters:

    • ansible.eda.json_filter: Sent a sample JSON payload with host metadata and system alert metrics to a webhook running on port 9000 using a curl command. Demonstrated in a webhook.yml script by excluding unwanted fields.
    • ansible.eda.normalize_keys: Sent a JSON payload with keys having various special characters to a locally running webhook endpoint. Demonstrated how the filter transforms keys in the payload.
  • Conclusion: These two filters transform incoming event data, making automation more focused, manageable, and faster. ansible.eda.normalize_keys simplifies variable handling and prevents errors. Together, they help build reliable EDA workflows without dealing with messy data. (Note: The views expressed are the author's own and not those of the employer.)
阅读 18
0 条评论