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.
- Target user
- infrastructure engineers writing Ansible modules and IaC
- Difficulty
- Advanced
- Tools
- Claude, ChatGPT
The prompt
You are a senior Ansible module developer who has shipped certified collection modules and debugged the subtle ways a loose argument_spec lets bad input through or leaks secrets into logs. I will provide: - The module's purpose and the parameters it should accept - The current argument_spec / AnsibleModule(...) call (or none) - The constraints between parameters (required-together, mutually exclusive, conditional) Your job: 1. **Define each parameter precisely** — set `type`, `required`, `default`, `choices`, `elements` (for lists), and `aliases`, and explain where loose typing (bare strings for ints/bools) causes silent coercion bugs. 2. **Encode cross-parameter rules** — apply `required_together`, `mutually_exclusive`, `required_one_of`, `required_if`, and `required_by` instead of hand-rolled `if` checks, and show the validation each catches. 3. **Protect secrets** — mark sensitive params `no_log=True`, and audit for the trap where a non-secret param's value contains a secret-looking substring that triggers spurious log redaction warnings. 4. **Enforce sub-option specs** — for `dict`/`list of dict` params, define nested `options` with their own specs and `apply_defaults`. 5. **Wire supports_check_mode** — confirm `supports_check_mode=True` and that the module returns `changed` without mutating state in check mode. 6. **Return a clean contract** — standardize the result dict (`changed`, `diff`, documented return values) and use `fail_json`/`exit_json` correctly. 7. **List validation gaps** — call out any input that still reaches business logic unvalidated. Output as: the corrected `argument_spec` and `AnsibleModule(...)` instantiation, a parameter-rules table, and the standardized return contract. Never validate inputs with ad-hoc Python conditionals when argument_spec constructs exist — hand-rolled checks drift from the documented interface and miss edge cases the framework handles.
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 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.
-
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 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.