cisco.ios.ios_hsrp_interfaces module – Resource module to configure HSRP on interfaces.

Note

This module is part of the cisco.ios collection (version 11.0.0).

You might already have this collection installed if you are using the ansible package. It is not included in ansible-core. To check whether it is installed, run ansible-galaxy collection list.

To install it, use: ansible-galaxy collection install cisco.ios.

To use it in a playbook, specify: cisco.ios.ios_hsrp_interfaces.

New in cisco.ios 10.1.0

Synopsis

  • This module provides declarative management of HSRP configuration on interface for Cisco IOS devices.

Parameters

Parameter

Comments

config

list / elements=dictionary

A list of HSP configuration options to add to interface

bfd

boolean

Enable HSRP BFD

Choices:

  • false

  • true

delay

dictionary

HSRP initialization delay

minimum

integer

Delay at least this long

reload

integer

Delay after reload

follow

string

Name of HSRP group to follow

mac_refresh

integer

Refresh MAC cache on switch by periodically sending packet from virtual mac address

name

string / required

Full name of the interface excluding any logical unit number, i.e. GigabitEthernet0/1.

redirect

dictionary

Redirect configuration

advertisement

dictionary

Redirect advertisement messages (standby redirect advertisement authentication md5)

authentication

dictionary

Authentication configuration

encryption

string

Set encryption 0 (unencrypted/default) or 7 (hidden)

key_chain

string

Set key chain

key_string

boolean

Set key string

Choices:

  • false

  • true

password_text

string

Password text valid for plain text and and key-string

time_out

integer

Set timeout

timers

dictionary

Adjust redirect timers

adv_timer

integer

Passive router advertisement interval in seconds

holddown_timer

integer

Passive router holddown interval in seconds

standby_groups

list / elements=dictionary

Group number and group options for standby (HSRP)

authentication

dictionary

Authentication configuration

advertisement

dictionary

Redirect advertisement messages (standby redirect advertisement authentication md5)

encryption

integer

Set encryption 0 (unencrypted/default) or 7 (hidden)

key_chain

string

Set key chain

key_string

boolean

Set key string

Choices:

  • false

  • true

password_text

string

Password text valid for plain text and and key-string

text

dictionary

Password text valid for plain text

password_text

string

Password text valid for plain text and and key-string

time_out

integer

Set timeout

follow

string

Enable HSRP BFD

group_name

string

Redundancy name string

group_no

integer

Group number

ip

list / elements=dictionary

Enable HSRP IPv4 and set the virtual IP address

secondary

boolean

Make this IP address a secondary virtual IP address

Choices:

  • false

  • true

virtual_ip

string

Virtual IP address

ipv6

list / elements=dictionary

Enable HSRP IPv6 and set the IP address

autoconfig

boolean

Obtain address using autoconfiguration

Choices:

  • false

  • true

string

X:x:X:x::X IPv6 link-local address

ipv6_prefix

string

X:x:X:x::X/<0-128> IPv6 prefix

mac_address

string

Virtual MAC address

preempt

dictionary

Overthrow lower priority Active routers

delay

boolean

Wait before preempting

Choices:

  • false

  • true

enabled

boolean

Enables preempt, drives the lone `standby <grp_no> preempt` command

Choices:

  • false

  • true

minimum

integer

Delay at least this long

reload

integer

Delay after reload

sync

integer

Wait for IP redundancy clients

priority

integer

Priority level

timers

dictionary

Overthrow lower priority Active routers

hello_interval

integer

Hello interval in seconds

hold_time

integer

Hold time in seconds

msec

dictionary

Specify hello interval in milliseconds

hello_interval

integer

<15-999> Hello interval in milliseconds

hold_time

integer

<60-3000> Hold time in milliseconds

track

list / elements=dictionary

Priority tracking

decrement

integer

Priority decrement

shutdown

boolean

Shutdown Group

Choices:

  • false

  • true

track_no

integer

Track object number

use_bia

dictionary

HSRP uses interface’s burned in address (does not work with mac address)

scope

dictionary

Scope interface option

interface

boolean

Use-bia applies to all groups on this interface or sub-interface

Choices:

  • false

  • true

version

integer

HSRP version

running_config

string

This option is used only with state parsed.

The value of this option should be the output received from the IOS device by executing the command show running-config | section ^interface.

The state parsed reads the configuration from running_config option and transforms it into Ansible structured data as per the resource module’s argspec and the value is then returned in the parsed key within the result.

state

string

The state the configuration should be left in

The states rendered, gathered and parsed does not perform any change on the device.

The state rendered will transform the configuration in config option to platform specific CLI commands which will be returned in the rendered key within the result. For state rendered active connection to remote host is not required.

The state gathered will fetch the running configuration from device and transform it into structured data in the format as per the resource module argspec and the value is returned in the gathered key within the result.

The state parsed reads the configuration from running_config option and transforms it into JSON format as per the resource module parameters and the value is returned in the parsed key within the result. The value of running_config option should be the same format as the output of command show running-config | section ^interface executed on device. For state parsed active connection to remote host is not required.

Choices:

  • "merged" ← (default)

  • "replaced"

  • "overridden"

  • "deleted"

  • "rendered"

  • "gathered"

  • "parsed"

Notes

Note

Examples

# Using merged

# Before state:
# -------------
#
# Router#show running-config | section ^interface
# interface Loopback888
#  no ip address
# interface Loopback999
#  no ip address
# interface GigabitEthernet1
#  description Management interface do not change
#  ip address dhcp
#  negotiation auto
# interface GigabitEthernet2
#  no ip address
#  ip ospf network broadcast
#  ip ospf resync-timeout 10
#  ip ospf dead-interval 5
#  speed 1000
#  no negotiation auto
# interface GigabitEthernet3
#  no ip address
#  speed 1000
#  no negotiation auto
# interface GigabitEthernet4
#  no ip address
#  shutdown
#  negotiation auto

- name: Merge provided configuration with device configuration
  cisco.ios.ios_hsrp_interfaces:
    config:
      - name: GigabitEthernet3
        standby_groups:
          - group_no: 22
            ip:
              - virtual_ip: 10.0.0.1
                secondary: true
      - name: GigabitEthernet4
        standby_groups:
          - group_no: 0
            priority: 5
    state: merged

# Task Output
# -----------
#
# before:
# - name: GigabitEthernet1
# - name: GigabitEthernet2
# - name: GigabitEthernet3
# - name: GigabitEthernet4
# - name: Loopback999
# - name: Loopback888
# commands:
# - interface GigabitEthernet3
# - standby 22 ip 10.0.0.1 secondary
# - interface GigabitEthernet4
# - standby 0 priority 5
# after:
#   name: GigabitEthernet1
#   name: GigabitEthernet2
#   name: GigabitEthernet3
#     standby_groups:
#       - group_no: 22
#         ip:
#           - virtual_ip: 192.168.0.2
#             secondary: True
# - name: GigabitEthernet4
#     standby_groups:
#       - group_no: 0
#         priority: 5
# - name: Loopback999
# - name: Loopback888

# After state:
# ------------
#
# interface Loopback888
#  no ip address
# interface Loopback999
#  no ip address
# interface GigabitEthernet1
#  description Management interface do not change
#  ip address dhcp
#  negotiation auto
# interface GigabitEthernet2
#  no ip address
#  speed 1000
#  no negotiation auto
# interface GigabitEthernet3
#  no ip address
#  speed 1000
#  standby 22 ip 10.0.0.1 secondary
#  no negotiation auto
# interface GigabitEthernet4
#  no ip address
#  standby 0 priority 5
#  shutdown
#  negotiation auto


# Using replaced

# Before state:
# -------------
#
# Router#show running-config | section ^interface
# interface Loopback888
#  no ip address
# interface Loopback999
#  no ip address
# interface GigabitEthernet1
#  description Management interface do not change
#  ip address dhcp
#  negotiation auto
# interface GigabitEthernet2
#  no ip address
#  speed 1000
#  no negotiation auto
# interface GigabitEthernet3
#  no ip address
#  speed 1000
#  standby 22 ip 10.0.0.1 secondary
#  no negotiation auto
# interface GigabitEthernet4
#  no ip address
#  standby 0 priority 5
#  shutdown
#  negotiation auto

- name: Replaces device configuration of listed interfaces with provided configuration
  cisco.ios.ios_hsrp_interfaces:
    config:
      - name: GigabitEthernet3
        standby_groups:
          - group_no: 22
            ip:
              - virtual_ip: 10.0.0.1
                secondary: true
      - name: GigabitEthernet4
        standby_groups:
          - group_no: 0
            priority: 6
    state: replaced

# Task Output
# -----------
#
# before:
# - name: GigabitEthernet1
# - name: GigabitEthernet2
# - name: GigabitEthernet3
#     standby_groups:
#       - group_no: 22
#         ip:
#           - virtual_ip: 192.168.0.2
#             secondary: True
# - name: GigabitEthernet4
#     standby_groups:
#       - group_no: 0
#         priority: 6
# - name: Loopback999
# - name: Loopback888
# commands:
# - interface GigabitEthernet3
# - standby 22 ip 10.0.0.1 secondary
# - interface GigabitEthernet4
# - standby 0 priority 5
# after:
#   name: GigabitEthernet1
#   name: GigabitEthernet2
#   name: GigabitEthernet3
#     standby_groups:
#       - group_no: 22
#         ip:
#           - virtual_ip: 192.168.0.2
#             secondary: True
# - name: GigabitEthernet4
#     standby_groups:
#       - group_no: 0
#         priority: 6
# - name: Loopback999
# - name: Loopback888

# After state:
# ------------
#
# interface Loopback888
#  no ip address
# interface Loopback999
#  no ip address
# interface GigabitEthernet1
#  description Management interface do not change
#  ip address dhcp
#  negotiation auto
# interface GigabitEthernet2
#  no ip address
#  ip ospf network broadcast
#  ip ospf resync-timeout 10
#  ip ospf dead-interval 5
#  speed 1000
#  no negotiation auto
# interface GigabitEthernet3
#  no ip address
#  standby 22 ip 10.0.0.1 secondary
#  speed 1000
#  no negotiation auto
# interface GigabitEthernet4
#  description Auto_Cable_Testing_Ansible
#  no ip address
#  standby 0 priority 6
#  shutdown
#  negotiation auto

# Using overridden

# Before state:
# -------------
#
# interface Loopback888
#  no ip address
# interface Loopback999
#  no ip address
# interface GigabitEthernet1
#  description Management interface do not change
#  ip address dhcp
#  negotiation auto
# interface GigabitEthernet2
#  no ip address
#  ip ospf network broadcast
#  ip ospf resync-timeout 10
#  ip ospf dead-interval 5
#  speed 1000
#  no negotiation auto
# interface GigabitEthernet3
#  no ip address
#  standby 22 ip 10.0.0.1 secondary
#  speed 1000
#  no negotiation auto
# interface GigabitEthernet4
#  description Auto_Cable_Testing_Ansible
#  no ip address
#  standby 0 priority 6
#  shutdown
#  negotiation auto

- name: Override device configuration of all interfaces with provided configuration
  cisco.ios.ios_hsrp_interfaces:
    config:
      - name: GigabitEthernet4
        standby_groups:
          - group_no: 0
            priority: 10
    state: overridden

# Task Output
# -----------
# before:
# - name: GigabitEthernet1
# - name: GigabitEthernet2
# - name: GigabitEthernet3
#     standby_groups:
#       - group_no: 22
#         ip:
#           - virtual_ip: 192.168.0.2
#             secondary: True
# - name: GigabitEthernet4
#     standby_groups:
#       - group_no: 0
#         priority: 6
# - name: Loopback999
# - name: Loopback888
# commands:
# - interface GigabitEthernet3
# - no standby 22 ip 10.0.0.1 secondary
# - interface GigabitEthernet4
# - no standby 0 priority 6
# - standby 0 priority 10
# after:
# - name: GigabitEthernet1
# - name: GigabitEthernet2
# - name: GigabitEthernet3
# - name: GigabitEthernet4
#     standby_groups:
#       - group_no: 0
#         priority: 10
# - name: Loopback999
# - name: Loopback888

# After state:
# ------------
#
# router-ios#show running-config | section ^interface
# interface Loopback888
#  no ip address
# interface Loopback999
#  no ip address
# interface GigabitEthernet1
#  description Management interface do not change
#  ip address dhcp
#  negotiation auto
# interface GigabitEthernet2
#  no ip address
#  ip ospf network broadcast
#  ip ospf resync-timeout 10
#  ip ospf dead-interval 5
#  speed 1000
#  no negotiation auto
# interface GigabitEthernet3
#  no ip address
#  speed 1000
#  no negotiation auto
# interface GigabitEthernet4
#  description Auto_Cable_Testing_Ansible
#  no ip address
#  standby 0 priority 10
#  shutdown
#  negotiation auto

# Using deleted

# Before state:
# -------------
#
# router-ios#show running-config | section ^interface
# interface Loopback888
#  no ip address
# interface Loopback999
#  no ip address
# interface GigabitEthernet1
#  description Management interface do not change
#  ip address dhcp
#  negotiation auto
# interface GigabitEthernet2
#  no ip address
#  ip ospf network broadcast
#  ip ospf resync-timeout 10
#  ip ospf dead-interval 5
#  speed 1000
#  no negotiation auto
# interface GigabitEthernet3
#  no ip address
#  speed 1000
#  no negotiation auto
# interface GigabitEthernet4
#  description Auto_Cable_Testing_Ansible
#  no ip address
#  standby 0 priority 10
#  shutdown
#  negotiation auto

- name: "Delete attributes of given interfaces (NOTE: This won't delete the interfaces)"
  cisco.ios.ios_hsrp_interfaces:
    config:
      - name: GigabitEthernet4
    state: deleted

# Task Output
# -----------
#
# before:
# - name: GigabitEthernet1
# - name: GigabitEthernet2
# - name: GigabitEthernet3
# - name: GigabitEthernet4
#     standby_groups:
#       - group_no: 0
#         priority: 10
# - name: Loopback999
# - name: Loopback888
# commands:
# - interface GigabitEthernet4
# - no standby 0 priority 10
# after:
#   name: GigabitEthernet1
# - name: GigabitEthernet2
# - name: GigabitEthernet3
# - name: GigabitEthernet4
# - name: Loopback999
# - name: Loopback888

# After state:
# -------------
#
# router-ios#show running-config | section ^interface
# interface Loopback888
#  no ip address
# interface Loopback999
#  no ip address
# interface GigabitEthernet1
#  description Management interface do not change
#  ip address dhcp
#  negotiation auto
# interface GigabitEthernet2
#  no ip address
#  ip ospf network broadcast
#  ip ospf resync-timeout 10
#  ip ospf dead-interval 5
#  speed 1000
#  no negotiation auto
# interface GigabitEthernet3
#  no ip address
#  speed 1000
#  no negotiation auto
# interface GigabitEthernet4
#  description Auto_Cable_Testing_Ansible
#  no ip address
#  shutdown
#  negotiation auto

# Using deleted without config passed, only interface's configuration will be negated

# Before state:
# -------------

# interface Loopback888
#  no ip address
# interface Loopback999
#  no ip address
# interface GigabitEthernet1
#  description Management interface do not change
#  ip address dhcp
#  negotiation auto
# interface GigabitEthernet2
#  no ip address
#  speed 1000
#  no negotiation auto
# interface GigabitEthernet3
#  no ip address
#  speed 1000
#  standby 22 ip 10.0.0.1 secondary
#  no negotiation auto
# interface GigabitEthernet4
#  no ip address
#  standby 0 priority 5
#  shutdown
#  negotiation auto

- name: "Delete HSRP config of all interfaces"
  cisco.ios.ios_hsrp_interfaces:
    state: deleted

# Task Output
# -----------
#
# before:
# - name: GigabitEthernet1
# - name: GigabitEthernet2
# - name: GigabitEthernet3
#     standby_groups:
#       - group_no: 22
#         ip:
#           - virtual_ip: 192.168.0.2
#             secondary: True
# - name: GigabitEthernet4
#     standby_groups:
#       - group_no: 0
#         priority: 5
# - name: Loopback999
# - name: Loopback888
# commands:
# - interface GigabitEthernet3
# - no standby 22 ip 192.168.0.2 secondary
# - interface GigabitEthernet4
# - no standby 0 priority 5
# after:
# - name: GigabitEthernet1
# - name: GigabitEthernet2
# - name: GigabitEthernet3
# - name: GigabitEthernet3.100
# - name: GigabitEthernet4
# - name: Loopback999

# After state:
# -------------
#
# interface Loopback888
#  no ip address
# interface Loopback999
#  no ip address
# interface GigabitEthernet1
#  description Management interface do not change
#  ip address dhcp
#  negotiation auto
# interface GigabitEthernet2
#  no ip address
#  ip ospf network broadcast
#  ip ospf resync-timeout 10
#  ip ospf dead-interval 5
#  speed 1000
#  no negotiation auto
# interface GigabitEthernet3
#  no ip address
#  speed 1000
#  no negotiation auto
# interface GigabitEthernet4
#  description Auto_Cable_Testing_Ansible
#  no ip address
#  shutdown
#  negotiation auto

# Using gathered

# Before state:
# -------------
# interface Loopback888
#  no ip address
# interface Loopback999
#  no ip address
# interface GigabitEthernet1
#  description Management interface do not change
#  ip address dhcp
#  negotiation auto
# interface GigabitEthernet2
#  no ip address
#  speed 1000
#  no negotiation auto
# interface GigabitEthernet3
#  no ip address
#  speed 1000
#  standby 22 ip 10.0.0.1 secondary
#  no negotiation auto
# interface GigabitEthernet4
#  no ip address
#  standby 0 priority 5
#  shutdown
#  negotiation auto

- name: Gather facts for hsrp interfaces
  cisco.ios.ios_hsrp_interfaces:
    state: gathered

# Task Output
# -----------
#
# gathered:
# - name: GigabitEthernet1
# - name: GigabitEthernet2
# - name: GigabitEthernet3
#     standby_groups:
#       - group_no: 22
#         ip:
#           - virtual_ip: 192.168.0.2
#             secondary: True
# - name: GigabitEthernet4
#     standby_groups:
#       - group_no: 0
#         priority: 5
# - name: Loopback999
# - name: Loopback888

# Using rendered

- name: Render the commands for provided configuration
  cisco.ios.ios_hsrp_interfaces:
    config:
      - name: GigabitEthernet3
        standby_groups:
          - group_no: 22
            ip:
              - virtual_ip: 192.168.0.2
                secondary: true
      - name: GigabitEthernet4
        standby_groups:
          - group_no: 0
            priority: 5
    state: rendered

# Task Output
# -----------
#
# rendered:
# - interface GigabitEthernet3
# - "standby 22 ip 10.0.0.1 secondary
# - interface GigabitEthernet4
# - standby 0 priority 5

# Using parsed

# File: parsed.cfg
# ----------------
#
# interface GigabitEthernet3
#  standby 22 ip 10.0.0.1 secondary
# interface GigabitEthernet4
#  standby 0 priority 5

# - name: Parse the provided configuration
#   cisco.ios.ios_hsrp_interfaces:
#     running_config: "{{ lookup('file', 'parsed.cfg') }}"
#     state: parsed

# Task Output
# -----------
#
# parsed:
# - name: GigabitEthernet3
#    standby_groups:
#     - group_no: 22
#       ip:
#         - virtual_ip: 192.168.0.2
#           secondary: True
# - name: GigabitEthernet4
#    standby_groups:
#     - group_no: 0
#       priority: 5

Return Values

Common return values are documented here, the following are the fields unique to this module:

Key

Description

after

dictionary

The resulting configuration after module execution.

Returned: when changed

Sample: "This output will always be in the same format as the module argspec.\n"

before

dictionary

The configuration prior to the module execution.

Returned: when state is merged, replaced, overridden, deleted or purged

Sample: "This output will always be in the same format as the module argspec.\n"

commands

list / elements=string

The set of commands pushed to the remote device.

Returned: when state is merged, replaced, overridden, deleted or purged

Sample: ["standby 22 ip 10.0.0.1 secondary", "standby 0 priority 5", "standby mac-refresh 21"]

gathered

list / elements=string

Facts about the network resource gathered from the remote device as structured data.

Returned: when state is gathered

Sample: ["This output will always be in the same format as the module argspec.\n"]

parsed

list / elements=string

The device native config provided in running_config option parsed into structured data as per module argspec.

Returned: when state is parsed

Sample: ["This output will always be in the same format as the module argspec.\n"]

rendered

list / elements=string

The provided configuration in the task rendered in device-native format (offline).

Returned: when state is rendered

Sample: ["standby 22 ip 10.0.0.1 secondary", "standby 0 priority 5", "standby mac-refresh 21"]

Authors

  • Sagar Paul (@KB-perByte)

  • Nikhil Bhasin (@nickbhasin)