Ansible Custom Lookup Plugin Prompt
Build a custom Ansible lookup plugin that fetches data from an external source at templating time, with caching and error handling.
- Target user
- Ansible engineers integrating external data sources into playbooks
- Difficulty
- Advanced
- Tools
- Claude, ChatGPT
The prompt
You are a senior infrastructure-as-code engineer who writes Ansible lookup plugins that pull secrets and config from internal APIs without leaking them into logs. I will provide: - The external source the lookup must query (API, file, DB, secrets manager) - The arguments callers will pass and the return shape they expect - Sensitivity of the data and any caching constraints Your job: 1. **Confirm the contract** — verify the plugin subclasses `LookupBase` and implements `run(self, terms, variables=None, **kwargs)` returning a list. 2. **Parse arguments** — handle positional `terms` and keyword options via `self.set_options()` / `self.get_option()` with a documented option spec. 3. **Fetch resiliently** — add timeouts, retries with backoff, and raise `AnsibleError` with a clear message on failure rather than returning partial data. 4. **Protect secrets** — mark sensitive returns so they are not displayed, avoid logging values, and document that `no_log` should be set on the consuming task. 5. **Cache deliberately** — decide per-run vs cross-run caching and explain the staleness trade-off; default to no persistent cache for secrets. 6. **Test** — provide pytest cases mocking the external source for success, timeout, and not-found, plus a playbook usage snippet with `lookup()` and `query()`. Output as: annotated Python plugin with DOCUMENTATION block, pytest file, and a playbook usage example showing safe consumption. Call out that lookups run on the controller, not the target — never assume target-node network access or filesystem.
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
-
Ansible Custom Filter Plugin Prompt
Design and review a custom Ansible Jinja2 filter plugin in Python — FilterModule contract, edge-case handling, and unit tests.
-
Ansible Runner Python Embedding Prompt
Embed Ansible into a Python service using the ansible-runner library — private data dir, event callbacks, artifacts, and status handling.
-
Ansible Module Argument Spec Validation Prompt
Design and review the argument_spec for a custom Ansible module so inputs are validated, mutually exclusive options are enforced, no_log secrets are protected, and check mode behaves correctly.
-
Ansible NX-OS and IOS Network Modules Prompt
Write idempotent Ansible playbooks for Cisco NX-OS and IOS devices using resource modules, with safe config replace and rollback.
More Infrastructure as Code prompts & error guides
Browse every Infrastructure as Code prompt and troubleshooting guide in one place.
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.