What are Ansible network resource modules, and what is the difference between merged, replaced and overridden?
Show the answer
Say this first
Resource modules manage one feature as structured data, for example cisco.ios.ios_vlans or
ios_l3_interfaces, instead of raw CLI lines. The state decides how. merged adds or updates what you
list and leaves the rest. replaced makes each listed item match exactly, removing attributes you left
out. overridden makes the whole resource on the device match your list, which deletes anything not
listed. deleted removes, and gathered, rendered and parsed read or convert without changing anything.
Go deeper
The states
| State | Touches the device | Effect |
|---|---|---|
merged | Yes | Add or update listed items; leave others alone |
replaced | Yes | Listed items match exactly; unlisted items untouched |
overridden | Yes | Whole resource matches the list; unlisted items removed |
deleted | Yes | Remove listed items, or all if none listed |
gathered | Reads | Return the current config as structured data |
rendered | No | Return the CLI commands the config would produce, offline |
parsed | No | Turn running-config text you supply into structured data |
Example
- name: Access VLANs
cisco.ios.ios_vlans:
config:
- vlan_id: 10
name: USERS
- vlan_id: 20
name: VOICE
- vlan_id: 30
name: GUESTS
state: mergedThe result holds before, after and commands. If only VLAN 30 is new, commands is
["vlan 30", "name GUESTS"].
Why they beat ios_config lines
The module understands the feature, so it knows that shutdown is the opposite of no shutdown, removes
attributes correctly in replaced, and stays idempotent without you matching running-config text.
They will ask next
When would you use overridden?
When the source of truth is complete for that resource and the device must match it exactly, such as the VLAN list on a leaf switch. Run it in check mode first: a missing VLAN in your data deletes a VLAN in production.
How do resource modules help with brownfield onboarding?
gatheredpulls today's config as structured data you can store as variables, andparseddoes the same from saved config backups without touching the device. That gives you a starting data model that matches reality.
Traps
- Using
overriddenwith incomplete data. It removes everything you did not list. - Assuming
replacedremoves unlisted VLANs. It only rewrites the ones you list.