Static routes resource module
Version added: 1.0.0
- This module manages attributes of static routes on VyOS network devices.
Note
- Tested against VyOS 1.1.8 (helium).
- This module works with connection
ansible.netcommon.network_cli
. See the VyOS OS Platform Options.
# Using merged
#
# Before state:
# -------------
#
# vyos@vyos:~$ show configuration commands | grep static
#
- name: Merge the provided configuration with the existing running configuration
vyos.vyos.vyos_static_routes:
config:
- address_families:
- afi: ipv4
routes:
- dest: 192.0.2.32/28
blackhole_config:
type: blackhole
next_hops:
- forward_router_address: 192.0.2.6
- forward_router_address: 192.0.2.7
- address_families:
- afi: ipv6
routes:
- dest: '2001:db8:1000::/36'
blackhole_config:
distance: 2
next_hops:
- forward_router_address: '2001:db8:2000:2::1'
- forward_router_address: '2001:db8:2000:2::2'
state: merged
#
#
# -------------------------
# Module Execution Result
# -------------------------
#
# before": []
#
# "commands": [
# "set protocols static route 192.0.2.32/28",
# "set protocols static route 192.0.2.32/28 blackhole",
# "set protocols static route 192.0.2.32/28 next-hop '192.0.2.6'",
# "set protocols static route 192.0.2.32/28 next-hop '192.0.2.7'",
# "set protocols static route6 2001:db8:1000::/36",
# "set protocols static route6 2001:db8:1000::/36 blackhole distance '2'",
# "set protocols static route6 2001:db8:1000::/36 next-hop '2001:db8:2000:2::1'",
# "set protocols static route6 2001:db8:1000::/36 next-hop '2001:db8:2000:2::2'"
# ]
#
# "after": [
# {
# "address_families": [
# {
# "afi": "ipv4",
# "routes": [
# {
# "blackhole_config": {
# "type": "blackhole"
# },
# "dest": "192.0.2.32/28",
# "next_hops": [
# {
# "forward_router_address": "192.0.2.6"
# },
# {
# "forward_router_address": "192.0.2.7"
# }
# ]
# }
# ]
# },
# {
# "afi": "ipv6",
# "routes": [
# {
# "blackhole_config": {
# "distance": 2
# },
# "dest": "2001:db8:1000::/36",
# "next_hops": [
# {
# "forward_router_address": "2001:db8:2000:2::1"
# },
# {
# "forward_router_address": "2001:db8:2000:2::2"
# }
# ]
# }
# ]
# }
# ]
# }
# ]
#
# After state:
# -------------
#
# vyos@vyos:~$ show configuration commands| grep static
# set protocols static route 192.0.2.32/28 'blackhole'
# set protocols static route 192.0.2.32/28 next-hop '192.0.2.6'
# set protocols static route 192.0.2.32/28 next-hop '192.0.2.7'
# set protocols static route6 2001:db8:1000::/36 blackhole distance '2'
# set protocols static route6 2001:db8:1000::/36 next-hop '2001:db8:2000:2::1'
# set protocols static route6 2001:db8:1000::/36 next-hop '2001:db8:2000:2::2'
# Using replaced
#
# Before state:
# -------------
#
# vyos@vyos:~$ show configuration commands| grep static
# set protocols static route 192.0.2.32/28 'blackhole'
# set protocols static route 192.0.2.32/28 next-hop '192.0.2.6'
# set protocols static route 192.0.2.32/28 next-hop '192.0.2.7'
# set protocols static route 192.0.2.33/28 'blackhole'
# set protocols static route 192.0.2.33/28 next-hop '192.0.2.3'
# set protocols static route 192.0.2.33/28 next-hop '192.0.2.4'
# set protocols static route6 2001:db8:1000::/36 blackhole distance '2'
# set protocols static route6 2001:db8:1000::/36 next-hop '2001:db8:2000:2::1'
# set protocols static route6 2001:db8:1000::/36 next-hop '2001:db8:2000:2::2'
#
- name: Replace device configurations of listed static routes with provided configurations
vyos.vyos.vyos_static_routes:
config:
- address_families:
- afi: ipv4
routes:
- dest: 192.0.2.32/28
blackhole_config:
distance: 2
next_hops:
- forward_router_address: 192.0.2.7
enabled: false
- forward_router_address: 192.0.2.9
state: replaced
#
#
# -------------------------
# Module Execution Result
# -------------------------
#
# "before": [
# {
# "address_families": [
# {
# "afi": "ipv4",
# "routes": [
# {
# "blackhole_config": {
# "type": "blackhole"
# },
# "dest": "192.0.2.32/28",
# "next_hops": [
# {
# "forward_router_address": "192.0.2.6"
# },
# {
# "forward_router_address": "192.0.2.7"
# }
# ]
# },
# {
# "blackhole_config": {
# "type": "blackhole"
# },
# "dest": "192.0.2.33/28",
# "next_hops": [
# {
# "forward_router_address": "192.0.2.3"
# },
# {
# "forward_router_address": "192.0.2.4"
# }
# ]
# }
# ]
# },
# {
# "afi": "ipv6",
# "routes": [
# {
# "blackhole_config": {
# "distance": 2
# },
# "dest": "2001:db8:1000::/36",
# "next_hops": [
# {
# "forward_router_address": "2001:db8:2000:2::1"
# },
# {
# "forward_router_address": "2001:db8:2000:2::2"
# }
# ]
# }
# ]
# }
# ]
# }
# ]
#
# "commands": [
# "delete protocols static route 192.0.2.32/28 next-hop '192.0.2.6'",
# "delete protocols static route 192.0.2.32/28 next-hop '192.0.2.7'",
# "set protocols static route 192.0.2.32/28 next-hop 192.0.2.7 'disable'",
# "set protocols static route 192.0.2.32/28 next-hop '192.0.2.7'",
# "set protocols static route 192.0.2.32/28 next-hop '192.0.2.9'",
# "set protocols static route 192.0.2.32/28 blackhole distance '2'"
# ]
#
# "after": [
# {
# "address_families": [
# {
# "afi": "ipv4",
# "routes": [
# {
# "blackhole_config": {
# "distance": 2
# },
# "dest": "192.0.2.32/28",
# "next_hops": [
# {
# "enabled": false,
# "forward_router_address": "192.0.2.7"
# },
# {
# "forward_router_address": "192.0.2.9"
# }
# ]
# },
# {
# "blackhole_config": {
# "type": "blackhole"
# },
# "dest": "192.0.2.33/28",
# "next_hops": [
# {
# "forward_router_address": "192.0.2.3"
# },
# {
# "forward_router_address": "192.0.2.4"
# }
# ]
# }
# ]
# },
# {
# "afi": "ipv6",
# "routes": [
# {
# "blackhole_config": {
# "distance": 2
# },
# "dest": "2001:db8:1000::/36",
# "next_hops": [
# {
# "forward_router_address": "2001:db8:2000:2::1"
# },
# {
# "forward_router_address": "2001:db8:2000:2::2"
# }
# ]
# }
# ]
# }
# ]
# }
# ]
#
# After state:
# -------------
#
# vyos@vyos:~$ show configuration commands| grep static
# set protocols static route 192.0.2.32/28 blackhole distance '2'
# set protocols static route 192.0.2.32/28 next-hop 192.0.2.7 'disable'
# set protocols static route 192.0.2.32/28 next-hop '192.0.2.9'
# set protocols static route 192.0.2.33/28 'blackhole'
# set protocols static route 192.0.2.33/28 next-hop '192.0.2.3'
# set protocols static route 192.0.2.33/28 next-hop '192.0.2.4'
# set protocols static route6 2001:db8:1000::/36 blackhole distance '2'
# set protocols static route6 2001:db8:1000::/36 next-hop '2001:db8:2000:2::1'
# set protocols static route6 2001:db8:1000::/36 next-hop '2001:db8:2000:2::2'
# Using overridden
#
# Before state
# --------------
#
# vyos@vyos:~$ show configuration commands| grep static
# set protocols static route 192.0.2.32/28 blackhole distance '2'
# set protocols static route 192.0.2.32/28 next-hop 192.0.2.7 'disable'
# set protocols static route 192.0.2.32/28 next-hop '192.0.2.9'
# set protocols static route6 2001:db8:1000::/36 blackhole distance '2'
# set protocols static route6 2001:db8:1000::/36 next-hop '2001:db8:2000:2::1'
# set protocols static route6 2001:db8:1000::/36 next-hop '2001:db8:2000:2::2'
#
- name: Overrides all device configuration with provided configuration
vyos.vyos.vyos_static_routes:
config:
- address_families:
- afi: ipv4
routes:
- dest: 198.0.2.48/28
next_hops:
- forward_router_address: 192.0.2.18
state: overridden
#
#
# -------------------------
# Module Execution Result
# -------------------------
#
# "before": [
# {
# "address_families": [
# {
# "afi": "ipv4",
# "routes": [
# {
# "blackhole_config": {
# "distance": 2
# },
# "dest": "192.0.2.32/28",
# "next_hops": [
# {
# "enabled": false,
# "forward_router_address": "192.0.2.7"
# },
# {
# "forward_router_address": "192.0.2.9"
# }
# ]
# }
# ]
# },
# {
# "afi": "ipv6",
# "routes": [
# {
# "blackhole_config": {
# "distance": 2
# },
# "dest": "2001:db8:1000::/36",
# "next_hops": [
# {
# "forward_router_address": "2001:db8:2000:2::1"
# },
# {
# "forward_router_address": "2001:db8:2000:2::2"
# }
# ]
# }
# ]
# }
# ]
# }
# ]
#
# "commands": [
# "delete protocols static route 192.0.2.32/28",
# "delete protocols static route6 2001:db8:1000::/36",
# "set protocols static route 198.0.2.48/28",
# "set protocols static route 198.0.2.48/28 next-hop '192.0.2.18'"
#
#
# "after": [
# {
# "address_families": [
# {
# "afi": "ipv4",
# "routes": [
# {
# "dest": "198.0.2.48/28",
# "next_hops": [
# {
# "forward_router_address": "192.0.2.18"
# }
# ]
# }
# ]
# }
# ]
# }
# ]
#
#
# After state
# ------------
#
# vyos@vyos:~$ show configuration commands| grep static
# set protocols static route 198.0.2.48/28 next-hop '192.0.2.18'
# Using deleted to delete static route based on afi
#
# Before state
# -------------
#
# vyos@vyos:~$ show configuration commands| grep static
# set protocols static route 192.0.2.32/28 'blackhole'
# set protocols static route 192.0.2.32/28 next-hop '192.0.2.6'
# set protocols static route 192.0.2.32/28 next-hop '192.0.2.7'
# set protocols static route6 2001:db8:1000::/36 blackhole distance '2'
# set protocols static route6 2001:db8:1000::/36 next-hop '2001:db8:2000:2::1'
# set protocols static route6 2001:db8:1000::/36 next-hop '2001:db8:2000:2::2'
#
- name: Delete static route based on afi.
vyos.vyos.vyos_static_routes:
config:
- address_families:
- afi: ipv4
- afi: ipv6
state: deleted
#
#
# ------------------------
# Module Execution Results
# ------------------------
#
# "before": [
# {
# "address_families": [
# {
# "afi": "ipv4",
# "routes": [
# {
# "blackhole_config": {
# "type": "blackhole"
# },
# "dest": "192.0.2.32/28",
# "next_hops": [
# {
# "forward_router_address": "192.0.2.6"
# },
# {
# "forward_router_address": "192.0.2.7"
# }
# ]
# }
# ]
# },
# {
# "afi": "ipv6",
# "routes": [
# {
# "blackhole_config": {
# "distance": 2
# },
# "dest": "2001:db8:1000::/36",
# "next_hops": [
# {
# "forward_router_address": "2001:db8:2000:2::1"
# },
# {
# "forward_router_address": "2001:db8:2000:2::2"
# }
# ]
# }
# ]
# }
# ]
# }
# ]
# "commands": [
# "delete protocols static route",
# "delete protocols static route6"
# ]
#
# "after": []
# After state
# ------------
# vyos@vyos# run show configuration commands | grep static
# set protocols 'static'
# Using deleted to delete all the static routes when passes config is empty
#
# Before state
# -------------
#
# vyos@vyos:~$ show configuration commands| grep static
# set protocols static route 192.0.2.32/28 'blackhole'
# set protocols static route 192.0.2.32/28 next-hop '192.0.2.6'
# set protocols static route 192.0.2.32/28 next-hop '192.0.2.7'
# set protocols static route6 2001:db8:1000::/36 blackhole distance '2'
# set protocols static route6 2001:db8:1000::/36 next-hop '2001:db8:2000:2::1'
# set protocols static route6 2001:db8:1000::/36 next-hop '2001:db8:2000:2::2'
#
- name: Delete all the static routes.
vyos.vyos.vyos_static_routes:
config:
state: deleted
#
#
# ------------------------
# Module Execution Results
# ------------------------
#
# "before": [
# {
# "address_families": [
# {
# "afi": "ipv4",
# "routes": [
# {
# "blackhole_config": {
# "type": "blackhole"
# },
# "dest": "192.0.2.32/28",
# "next_hops": [
# {
# "forward_router_address": "192.0.2.6"
# },
# {
# "forward_router_address": "192.0.2.7"
# }
# ]
# }
# ]
# },
# {
# "afi": "ipv6",
# "routes": [
# {
# "blackhole_config": {
# "distance": 2
# },
# "dest": "2001:db8:1000::/36",
# "next_hops": [
# {
# "forward_router_address": "2001:db8:2000:2::1"
# },
# {
# "forward_router_address": "2001:db8:2000:2::2"
# }
# ]
# }
# ]
# }
# ]
# }
# ]
# "commands": [
# "delete protocols static route",
# "delete protocols static route6"
# ]
#
# "after": []
# After state
# ------------
# vyos@vyos# run show configuration commands | grep static
# set protocols 'static'
# Using rendered
#
#
- name: Render the commands for provided configuration
vyos.vyos.vyos_static_routes:
config:
- address_families:
- afi: ipv4
routes:
- dest: 192.0.2.32/28
blackhole_config:
type: blackhole
next_hops:
- forward_router_address: 192.0.2.6
- forward_router_address: 192.0.2.7
- address_families:
- afi: ipv6
routes:
- dest: 2001:db8:1000::/36
blackhole_config:
distance: 2
next_hops:
- forward_router_address: 2001:db8:2000:2::1
- forward_router_address: 2001:db8:2000:2::2
state: rendered
#
#
# -------------------------
# Module Execution Result
# -------------------------
#
#
# "rendered": [
# "set protocols static route 192.0.2.32/28",
# "set protocols static route 192.0.2.32/28 blackhole",
# "set protocols static route 192.0.2.32/28 next-hop '192.0.2.6'",
# "set protocols static route 192.0.2.32/28 next-hop '192.0.2.7'",
# "set protocols static route6 2001:db8:1000::/36",
# "set protocols static route6 2001:db8:1000::/36 blackhole distance '2'",
# "set protocols static route6 2001:db8:1000::/36 next-hop '2001:db8:2000:2::1'",
# "set protocols static route6 2001:db8:1000::/36 next-hop '2001:db8:2000:2::2'"
# ]
# Using parsed
#
#
- name: Parse the provided running configuration
vyos.vyos.vyos_static_routes:
running_config:
"set protocols static route 192.0.2.32/28 'blackhole'
set protocols static route 192.0.2.32/28 next-hop '192.0.2.6'
set protocols static route 192.0.2.32/28 next-hop '192.0.2.7'
set protocols static route6 2001:db8:1000::/36 blackhole distance '2'
set protocols static route6 2001:db8:1000::/36 next-hop '2001:db8:2000:2::1'
set protocols static route6 2001:db8:1000::/36 next-hop '2001:db8:2000:2::2'"
state: parsed
#
#
# -------------------------
# Module Execution Result
# -------------------------
#
#
# "parsed": [
# {
# "address_families": [
# {
# "afi": "ipv4",
# "routes": [
# {
# "blackhole_config": {
# "distance": 2
# },
# "dest": "192.0.2.32/28",
# "next_hops": [
# {
# "forward_router_address": "2001:db8:2000:2::2"
# }
# ]
# }
# ]
# },
# {
# "afi": "ipv6",
# "routes": [
# {
# "blackhole_config": {
# "distance": 2
# },
# "dest": "2001:db8:1000::/36",
# "next_hops": [
# {
# "forward_router_address": "2001:db8:2000:2::2"
# }
# ]
# }
# ]
# }
# ]
# }
# ]
# Using gathered
#
# Before state:
# -------------
#
# vyos@vyos:~$ show configuration commands| grep static
# set protocols static route 192.0.2.32/28 'blackhole'
# set protocols static route 192.0.2.32/28 next-hop '192.0.2.6'
# set protocols static route 192.0.2.32/28 next-hop '192.0.2.7'
# set protocols static route6 2001:db8:1000::/36 blackhole distance '2'
# set protocols static route6 2001:db8:1000::/36 next-hop '2001:db8:2000:2::1'
# set protocols static route6 2001:db8:1000::/36 next-hop '2001:db8:2000:2::2'
#
- name: Gather listed static routes with provided configurations
vyos.vyos.vyos_static_routes:
config:
state: gathered
#
#
# -------------------------
# Module Execution Result
# -------------------------
#
# "gathered": [
# {
# "address_families": [
# {
# "afi": "ipv4",
# "routes": [
# {
# "blackhole_config": {
# "type": "blackhole"
# },
# "dest": "192.0.2.32/28",
# "next_hops": [
# {
# "forward_router_address": "192.0.2.6"
# },
# {
# "forward_router_address": "192.0.2.7"
# }
# ]
# }
# ]
# },
# {
# "afi": "ipv6",
# "routes": [
# {
# "blackhole_config": {
# "distance": 2
# },
# "dest": "2001:db8:1000::/36",
# "next_hops": [
# {
# "forward_router_address": "2001:db8:2000:2::1"
# },
# {
# "forward_router_address": "2001:db8:2000:2::2"
# }
# ]
# }
# ]
# }
# ]
# }
# ]
#
#
# After state:
# -------------
#
# vyos@vyos:~$ show configuration commands| grep static
# set protocols static route 192.0.2.32/28 'blackhole'
# set protocols static route 192.0.2.32/28 next-hop '192.0.2.6'
# set protocols static route 192.0.2.32/28 next-hop '192.0.2.7'
# set protocols static route6 2001:db8:1000::/36 blackhole distance '2'
# set protocols static route6 2001:db8:1000::/36 next-hop '2001:db8:2000:2::1'
# set protocols static route6 2001:db8:1000::/36 next-hop '2001:db8:2000:2::2'
Common return values are documented here, the following are the fields unique to this module:
- Rohit Thakur (@rohitthakur2590)