Octet

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

StateTouches the deviceEffect
mergedYesAdd or update listed items; leave others alone
replacedYesListed items match exactly; unlisted items untouched
overriddenYesWhole resource matches the list; unlisted items removed
deletedYesRemove listed items, or all if none listed
gatheredReadsReturn the current config as structured data
renderedNoReturn the CLI commands the config would produce, offline
parsedNoTurn running-config text you supply into structured data

Example

YAML
- name: Access VLANs
  cisco.ios.ios_vlans:
    config:
      - vlan_id: 10
        name: USERS
      - vlan_id: 20
        name: VOICE
      - vlan_id: 30
        name: GUESTS
    state: merged

The 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.

Traps

  • Using overridden with incomplete data. It removes everything you did not list.
  • Assuming replaced removes unlisted VLANs. It only rewrites the ones you list.
How did you do?