Skip to content
🎉 Launch sale:50% off everything over $22 — automatically applied at checkout· ends Aug 2Shop the sale →
DevOps AI ToolKit
Newsletter
All prompts
AI for Infrastructure as Code Difficulty: Advanced ClaudeChatGPT

Ansible Custom Filter Plugin Prompt

Design and review a custom Ansible Jinja2 filter plugin in Python — FilterModule contract, edge-case handling, and unit tests.

Target user
Ansible engineers extending templating with reusable Python filters
Difficulty
Advanced
Tools
Claude, ChatGPT

The prompt

You are a senior infrastructure-as-code engineer who has shipped reusable Ansible collections and writes filter plugins that survive real inventory data.

I will provide:
- The transformation the filter must perform (input shape to output shape)
- The current filter code or a plain-language description
- Where it lives (playbook-local `filter_plugins/` or a collection's `plugins/filter/`)

Your job:

1. **Confirm the contract** — verify the plugin exposes a `FilterModule` class with a `filters()` method returning a dict of name to callable, and that each callable is a pure function.
2. **Harden the implementation** — add type checks, raise `AnsibleFilterError` (not bare exceptions) on bad input, and avoid mutating the argument in place.
3. **Handle edge cases** — empty lists, `None`, non-ASCII strings, and undefined variables; decide explicit behavior for each rather than letting tracebacks leak.
4. **Name and namespace correctly** — recommend a collection-qualified name (`my_org.my_coll.my_filter`) and flag collisions with builtin filters.
5. **Write unit tests** — provide pytest cases covering happy path, empty input, and error path, asserting the `AnsibleFilterError` message.
6. **Show usage** — give a playbook snippet using the filter in a template and via `{{ var | filter }}`.
7. **Document** — add a short docstring and a usage example block.

Output as: (a) annotated Python plugin, (b) pytest file, (c) playbook usage snippet, (d) a bullet list of edge cases handled.

Flag any filter that swallows errors silently or returns a different type depending on input — those cause silent data corruption downstream.

Run this prompt with AI

Test it, get an AI-improved version, or compare models — live in the Prompt Workspace. No copy-paste.

Related prompts

More Infrastructure as Code prompts & error guides

Browse every Infrastructure as Code prompt and troubleshooting guide in one place.

Free download · 368-page PDF

Reading prompts? Get all 500 in one free PDF

500 battle-tested, copy-paste AI prompts engineered by a senior systems engineer — every one with fill-in placeholders and safety/back-out notes. Drop your email and it's yours.

  • 500 prompts: Linux · Kubernetes · Terraform · OpenStack · GitLab · Docker · Monitoring · Incident Response
  • Instant PDF download — yours free, forever
  • Plus one practical AI-workflow email a week (no spam)

Single opt-in · unsubscribe anytime · no spam.