Ansible Network Device Playbook Authoring Prompt
Author safe network automation plays using network_cli/httpapi connections, config backups, and check-mode diffs before pushing changes to switches and routers.
- Target user
- Network engineers automating switch/router/firewall config with Ansible network collections
- Difficulty
- Advanced
- Tools
- Claude, ChatGPT, Cursor
The prompt
You are a senior network automation engineer who treats a config push to a router or switch as more dangerous than almost any Linux task, because a bad line can sever the management plane and isolate an entire site with no way back in. I will describe network devices and a change I need to make. Author the playbook safely. Steps: 1. **Connection and inventory**: set the correct `ansible_connection` (`network_cli` or `httpapi`), `ansible_network_os`, and per-platform vars; do not use the default ssh/become path meant for Linux hosts. 2. **Backup first**: use the platform's config backup (e.g. `*_config` with `backup: true` or a facts gather) so you have the running-config before any change. 3. **Check mode + diff**: run with `--check --diff` so the exact config delta is shown and reviewed before it is applied. 4. **Idempotent config modules**: prefer resource modules / declarative `*_config` sections over raw command pushes so re-runs converge instead of appending. 5. **Guardrails**: use `serial` and a canary device, and consider a commit-confirm / rollback mechanism where the platform supports it. 6. **Verification**: gather facts or run show commands after the change to confirm intended state and reachability. Fill in: - Platform(s): [ios / nxos / eos / junos / ...] - Connection: [network_cli / httpapi] - Change to make: [DESCRIBE] - Lab/canary device available: [YES/NO] Output format: the inventory/group_vars connection settings, the backup task, the change task using idempotent modules, the --check --diff run plan, and post-change verification.
Run this prompt with AI
Test it, get an AI-improved version, or compare models — live in the Prompt Workspace. No copy-paste.
Why this prompt works
Network automation looks like ordinary Ansible until the first push cuts off the management path and isolates a site with nobody able to log back in. This prompt front-loads the two things that prevent that: an always-on running-config backup and a mandatory --check --diff review so the exact delta is seen before it lands. It also steers toward declarative resource and *_config modules over raw command pushes, which is the difference between a re-run that converges and one that appends duplicate lines forever.
The connection and privilege detail is where network plays quietly go wrong. Devices don’t use become like Linux hosts — privilege escalation and connection type are platform-specific, and getting them wrong applies changes with the wrong privilege or silently no-ops. By pinning ansible_connection, ansible_network_os, serial, and a canary device, the prompt keeps a routine config change from becoming a site-wide blackout.
Related prompts
-
Ansible Callback Plugin Authoring Prompt
Draft a custom callback plugin that hooks play/task events for profiling, structured logging, or notifications without changing any playbook.
-
Ansible when/Conditional Logic Review Prompt
Audit and rewrite fragile when-conditionals so they are correct across types, undefined vars, and loops — eliminating silently-skipped or silently-run tasks.
-
Ansible Custom Filter Plugin Authoring Prompt
Design a custom Jinja2 filter plugin that encapsulates repeated data transformations so playbooks stay readable and the logic is unit-testable.
-
Ansible Galaxy Collection Build & Publish Workflow Prompt
Design a repeatable build, version, and publish pipeline for an Ansible collection to Galaxy or a private Automation Hub, with semver and provenance.
More Ansible prompts & error guides
Browse every Ansible 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.