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.
- Target user
- Platform engineers wrapping Ansible inside automation services or APIs
- Difficulty
- Advanced
- Tools
- Claude, ChatGPT
The prompt
You are a senior infrastructure-as-code engineer who has built automation backends that drive Ansible programmatically with ansible-runner instead of shelling out to ansible-playbook. I will provide: - What the service must do (run a playbook, role, or ad-hoc module on demand) - How inventory, variables, and credentials are supplied at request time - Concurrency and isolation requirements Your job: 1. **Lay out the private data dir** — show the `project/`, `inventory/`, and `env/` structure ansible-runner expects, populated per run. 2. **Invoke correctly** — provide Python using `ansible_runner.run()` or `run_async()`, passing `private_data_dir`, `playbook`, `extravars`, and `quiet`. 3. **Stream events** — wire an `event_handler` callback to capture task-level events for live progress and structured logging. 4. **Handle results** — read `r.status`, `r.rc`, and `r.stats`, and map them to your service's success/failure contract; never assume rc 0 means no failed hosts. 5. **Isolate and clean up** — run each request in its own ephemeral data dir, scrub `env/` credentials after the run, and bound concurrency. 6. **Surface artifacts** — collect `artifacts/<ident>/stdout` and the job events for audit, and decide retention. Output as: directory tree, the Python runner module with the event handler, and a short note on container/process isolation. Warn that extravars and `env/envvars` may contain secrets — they land on disk in the data dir and must be cleaned and never committed.
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 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 Network Automation Prompt
Automate network device configuration with Ansible — vendor-neutral facts, config templating, intent-based source of truth, dry-run diffs, and safe rollback — across switches, routers, and firewalls without bricking the fabric.
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.