Ansible for Network Automation
Key Takeaways
- Ansible is agentless: a control node reaches network devices over SSH or APIs—you do not install an Ansible agent on Huawei switches for typical automation.
- Core building blocks are inventory (which hosts), playbooks (what to do in YAML), and modules (reusable task units for network devices).
- Idempotency means re-running the same playbook converges to the desired state without blindly stacking duplicate harmful changes each run.
- Ansible is off-box and multi-device oriented; OPS is on-box—do not swap those locations on exam items.
- HCIA expects concepts and placement, not authoring large enterprise roles/collections from memory.
Ansible for Network Automation
Quick Answer: Ansible automates many devices from a control node using inventory, playbooks (YAML), and modules. It is agentless—typically SSH or APIs to network gear, no agent on the switch. Idempotent plays drive devices toward a declared state. Ansible runs off-box; OPS runs on-box.
After OPS, HCIA expects you to place the industry-standard off-box tool that appears in Huawei’s automation story: Ansible. You will not be graded as a Red Hat certified engineer; you will be graded on whether you understand how Ansible reaches devices, what a playbook is, and why re-running automation should be safe.
What Ansible is in one paragraph
Ansible is an automation engine. You describe the desired work in playbooks, list target machines in an inventory, and execute from a control node. For network devices, tasks often use network modules that issue CLI commands, structured config, or API calls. The control node orchestrates; the devices apply changes and return results.
Agentless architecture (exam favorite)
| Term | Meaning |
|---|---|
| Control node | Server or workstation where Ansible runs |
| Managed node / host | Device in the inventory (router, switch, Linux server) |
| Agentless | No permanent Ansible agent software required on the managed network device for normal operation |
| Connection | Commonly SSH for network CLI modules; some platforms use HTTP/API connections |
| Credentials | Stored securely (variables, vault patterns in real ops)—exam cares that auth is required, not vault syntax trivia |
Why agentless matters for network gear: Installing third-party agents on every campus switch is operationally painful and often unsupported. SSH-based or API-based automation matches how engineers already manage Huawei devices.
Exam trap wording
- Correct association: Ansible → agentless → SSH/API from control node
- Incorrect association: Ansible requires a Python agent installed on every access switch (that confuses older server-automation mental models or other tools)
- Incorrect association: Ansible playbooks execute inside OPS on the data plane chip
Inventory: which devices
Inventory answers “who am I automating?” Simple inventories group hosts:
| Inventory idea | Example grouping |
|---|---|
| By role | access_switches, core_switches, branch_routers |
| By site | campus_a, campus_b |
| By platform | vrp_switches, vrp_routers |
Variables can attach per group: management VRF name, NTP server, banner text, credential references. HCIA takeaway: inventory scopes the blast radius. A playbook aimed at access_switches should not accidentally rewrite the core.
Playbooks: what to do
A playbook is typically a YAML file describing plays. Each play maps hosts from inventory to a list of tasks. Tasks call modules with parameters.
Conceptual structure (read as structure, not a lab file to memorize line-for-line):
- name: Standardize campus access switches
hosts: access_switches
gather_facts: false
tasks:
- name: Ensure NTP server is configured
# network module placeholder
# commands or structured config toward VRP
- name: Deploy standard ACL snippet
# another task
| Playbook element | Role |
|---|---|
| Play | One mapping of hosts + tasks (+ vars) |
| Task | Single step with a name and module call |
| Module | Unit of work (run command, push config snippet, wait for reboot, etc.) |
| Handler (awareness) | Task that runs on notification—e.g., save only if something changed |
| YAML | Indentation-sensitive text format used for playbooks |
You should be able to say: playbooks declare automation steps in YAML; they are not Python source files (though Ansible itself is implemented in Python, exam items about your artifacts mean YAML playbooks).
Modules for network devices
Modules encapsulate common operations so playbooks stay readable. Network-oriented modules may:
- Open SSH and run show/display commands
- Push configuration lines or templates
- Retrieve facts (hostname, OS version, interface list)
- Enforce a configuration block and report changed/ok/failed
| Without modules | With modules |
|---|---|
| Every playbook reinvents SSH session handling | Session and device differences handled inside module design |
| Fragile string scraping only | More consistent args and return structures |
| Hard to share | Shared automation language across the team |
Huawei ecosystems may use community or vendor-oriented collections in real projects. HCIA cares about the module concept, not a catalog of every collection name.
Idempotency: safe to re-run
Idempotency means applying the same automation repeatedly yields the same desired end state without unnecessary side effects. If the NTP server is already correct, a good task reports ok (no change) instead of appending a duplicate broken line every night.
| Approach | Re-run behavior | Risk |
|---|---|---|
| Naive “always append these CLI lines” | May duplicate statements or create conflicts | Config bloat, outages |
| Idempotent “ensure this state” | Changes only when drift exists | Safer scheduled automation |
Exam phrasing: Why can you schedule the same playbook daily? → Because well-written automation is idempotent and converges to the intended configuration rather than blindly stacking changes.
Idempotency is a goal of good automation design. Not every raw CLI command sequence is inherently idempotent; modules and careful task design improve the property.
Ansible workflow for a campus change
- Define inventory — list management IPs / hostnames for target VRP devices; group them.
- Write or reuse a playbook — tasks for the change (banner, ACL, VLAN batch concept, NTP).
- Check connectivity — control node must reach SSH/API; ACLs on VTY must allow the automation source.
- Run in check/diff mode when available — preview impact before production (operational best practice).
- Execute playbook — review per-host results: ok / changed / failed.
- Verify — still use
displaythinking; automation does not remove validation. - Save — ensure device startup config is updated per your change process (explicit task or operational step).
Prerequisites checklist (troubleshooting automation “failures”)
| Check | Why it breaks Ansible |
|---|---|
| IP reachability to management interface | SSH never connects |
| SSH/STelnet enabled and permitted on VTY | Connection refused / protocol blocked |
| Correct credentials / privilege level | Auth failure or commands rejected |
| ACL on management path | Control node IP denied |
| Inventory typo | Wrong device or empty host group |
| Change window / lock policies | Human process blocks push |
Notice the overlap with the VRP remote-management chapter: automation rides the same SSH path humans use, which is exactly why agentless SSH design fits network devices.
Ansible versus OPS versus controller (placement table)
| Dimension | Ansible | OPS | iMaster NCE (concept) |
|---|---|---|---|
| Where it runs | Control node | On device | Controller platform |
| Typical scope | Many devices per play | Local device intelligence | Fabric / campus intent |
| Agent on device? | No (agentless) | N/A (native feature) | Device may have controller protocols/agents per design |
| Artifact you author | Playbooks, inventory | On-box Python scripts | Policies, services, templates in NCE |
| Best story | Standardized multi-device push/gather | Event-driven local reaction | SDN-oriented operations at scale |
Single sentence for H12-811: Use Ansible to push consistent configuration from a server across an inventory; use OPS when the device itself should run Python on an event.
Realistic multi-device example
Goal: ensure every access switch uses the same logging host and a standard login banner.
- Inventory group
access_switchescontains 40 management addresses. - Playbook tasks: configure info-center log host parameters (concept), set
header login/ banner style text per VRP syntax used in your lab, optionally save. - First run: 40 hosts changed.
- Second run the next day: 40 hosts ok if nothing drifted—idempotency demonstrated.
- One closet switch was offline: playbook reports failed/unreachable for that host only; others succeed—blast radius is per inventory host, not “all or nothing” by necessity.
What HCIA does not require
- Memorizing every Ansible module parameter
- Writing complex Jinja2 templates under time pressure
- Designing AWX/Tower cluster HA
- Claiming Ansible replaces NETCONF knowledge entirely—Ansible may use SSH/CLI or APIs underneath
Stay conceptual, accurate, and placement-focused.
Exam traps
- Agent required on switch — false for typical Ansible network automation; it is agentless.
- Ansible runs on the data plane ASIC — false; it runs on a control node.
- Playbooks are binary compiled programs — false; they are YAML automation descriptions.
- Idempotent means “runs only once ever” — false; it means safe/correct under re-application toward desired state.
- Ansible and OPS are interchangeable names — false; off-box vs on-box is the discriminating fact.
- Inventory is optional because Ansible broadcasts to the whole LAN — false; inventory selects targets.
Practice goals
- Define agentless automation and name the common transport to network devices.
- Map inventory, playbook, and module to one sentence each.
- Explain idempotency with a re-run example (changed vs ok).
- Contrast Ansible with OPS without using vague “both automate networks” wording.
Next, SNMP and Network Management Basics covers classical monitoring—manager, agent, MIB, Get/Set/Trap—and how it sits beside automation in FCAPS-style O&M.
Why is Ansible commonly described as agentless for network device automation?
In Ansible terminology, which artifact primarily lists the target hosts and groups to automate?
What does idempotency mean for a well-written Ansible network playbook?
Which statement correctly contrasts Ansible with Huawei OPS for HCIA-Datacom?