Skip to content

Latest commit

 

History

History
714 lines (650 loc) · 26.5 KB

junipernetworks.junos.junos_static_routes_module.rst

File metadata and controls

714 lines (650 loc) · 26.5 KB

junipernetworks.junos.junos_static_routes

Static routes resource module

Version added: 1.0.0

  • This module provides declarative management of static routes on Juniper JUNOS devices

The below requirements are needed on the host that executes this module.

  • ncclient (>=v0.6.4)
  • xmltodict (>=0.12)
Parameter Choices/Defaults Comments
config
list / elements=dictionary
A dictionary of static routes options
address_families
list / elements=dictionary
Address family to use for the static routes
afi
string / required
    Choices:
  • ipv4
  • ipv6
afi to use for the static routes
routes
list / elements=dictionary
Static route configuration
dest
string
Static route destination including prefix
metric
integer
Metric value for the static route
next_hop
list / elements=dictionary
Next hop to destination
forward_router_address
string
List of next hops
vrf
string
Virtual Routing and Forwarding (VRF) name
running_config
string
This option is used only with state parsed.
The value of this option should be the output received from the Junos device by executing the command show routing-options.
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
    Choices:
  • merged ←
  • replaced
  • overridden
  • deleted
  • gathered
  • rendered
  • parsed
The state the configuration should be left in

Note

  • This module requires the netconf system service be enabled on the device being managed.
  • This module works with connection netconf. See the Junos OS Platform Options.
  • Tested against JunOS v18.4R1
# Using deleted

# Before state
# ------------
#
# admin# show routing-options
# static {
#     route 192.168.47.0/24 next-hop 172.16.1.2;
#     route 192.168.16.0/24 next-hop 172.16.1.2;
# }

- name: Delete provided configuration (default operation is merge)
  junipernetworks.junos.junos_static_routes:
    config:
      - address_families:
          - afi: ipv4
            routes:
              - dest: 192.168.16.0/24
                next_hop:
                  - forward_router_address: 172.16.1.2
    state: deleted

# Task Output
# -----------
# before:
#   - address_families:
#       - afi: ipv4
#         routes:
#           - dest: 192.168.47.0/24
#             next_hop:
#               - forward_router_address: 172.16.1.2
#           - dest: 192.168.16.0/24
#             next_hop:
#               - forward_router_address: 172.16.1.2
# commands:
#   - '<nc:routing-options
#     xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0"><nc:static><nc:route
#     delete="delete"><nc:name>192.168.16.0/24</nc:name></nc:route></nc:static></nc:routing-options>'
#   - '<nc:routing-instances xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0"/>'
# after:
#   - address_families:
#       - afi: ipv4
#         routes:
#           - dest: 192.168.47.0/24
#             next_hop:
#               - forward_router_address: 172.16.1.2

# After state:
# ------------
#
# admin# show routing-options
# static {
#     route 192.168.47.0/24 next-hop 172.16.1.2;
# }

# Using merged

# Before state
# ------------
#
# admin# show routing-options
# static {
#     route 192.168.47.0/24 next-hop 172.16.1.2;
# }

- name: Merge provided configuration with device configuration (default operation
    is merge)
  junipernetworks.junos.junos_static_routes:
    config:
      - address_families:
          - afi: ipv4
            routes:
              - dest: 192.168.16.0/24
                next_hop:
                  - forward_router_address: 172.16.1.2
    state: merged

# Task Output
# -----------
# before:
#   - address_families:
#       - afi: ipv4
#         routes:
#           - dest: 192.168.47.0/24
#             next_hop:
#               - forward_router_address: 172.16.1.2
# commands:
#   - '<nc:routing-options
#     xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0"><nc:static><nc:route><nc:name>192.168.16.0/24</nc:name>
#     <nc:next-hop>172.16.1.2</nc:next-hop></nc:route></nc:static></nc:routing-options>'
#   - '<nc:routing-instances xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0"/>'
# after:
#   - address_families:
#       - afi: ipv4
#         routes:
#           - dest: 192.168.47.0/24
#             next_hop:
#               - forward_router_address: 172.16.1.2
#           - dest: 192.168.16.0/24
#             next_hop:
#               - forward_router_address: 172.16.1.2
# After state:
# ------------
#
# admin# show routing-options
# static {
#     route 192.168.47.0/24 next-hop 172.16.1.2;
#     route 192.168.16.0/24 next-hop 172.16.1.2;
# }

# Using overridden

# Before state
# ------------
#
# admin# show routing-options
# static {
#     route 192.168.47.0/24 next-hop 172.16.1.2;
#     route 192.168.16.0/24 next-hop 172.16.1.2;
# }

- name: Override running configuration with provided configuration (default operation
    is merge)
  junipernetworks.junos.junos_static_routes:
    config:
      - address_families:
          - afi: ipv4
            routes:
              - dest: 192.168.16.0/24
                next_hop:
                  - forward_router_address: 172.16.0.1
    state: overridden
# Task Output:
# ------------
# before:
#   - address_families:
#       - afi: ipv4
#         routes:
#           - dest: 192.168.47.0/24
#             next_hop:
#               - forward_router_address: 172.16.1.2
#           - dest: 192.168.16.0/24
#             next_hop:
#               - forward_router_address: 172.16.1.2
# commands:
#   - >-
#     <nc:routing-options
#     xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0"><nc:static><nc:route
#     delete="delete"><nc:name>192.168.47.0/24</nc:name></nc:route><nc:route
#     delete="delete"><nc:name>192.168.16.0/24</nc:name></nc:route></nc:static><nc:static><nc:route><nc:name>192.168.16.0/24</nc:name><nc:next-hop>172.16.0.1</nc:next-hop></nc:route></nc:static></nc:routing-options>
#   - '<nc:routing-instances xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0"/>'
# after:
#   - address_families:
#       - afi: ipv4
#         routes:
#           - dest: 192.168.16.0/24
#             next_hop:
#               - forward_router_address: 172.16.0.1

# After state:
# ------------
#
# admin# show routing-options
# static {
#     route 192.168.16.0/24 next-hop 172.16.0.1;
# }

# Using replaced

# Before state
# ------------
#
# admin# show routing-options
# static {
#     route 192.168.47.0/24 next-hop 172.16.1.2;
#     route 192.168.16.0/24 next-hop 172.16.1.2;
# }

- name: Replace provided configuration with device configuration (default operation
    is merge)
  junipernetworks.junos.junos_static_routes:
    config:
      - address_families:
          - afi: ipv4
            routes:
              - dest: 192.168.47.0/24
                next_hop:
                  - forward_router_address: 10.200.16.2
    state: replaced

# Task Output:
# ------------
# before:
#   - address_families:
#       - afi: ipv4
#         routes:
#           - dest: 192.168.47.0/24
#             next_hop:
#               - forward_router_address: 172.16.1.2
#           - dest: 192.168.16.0/24
#             next_hop:
#               - forward_router_address: 172.16.1.2
# commands:
#   - >-
#     <nc:routing-options
#     xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0"><nc:static><nc:route
#     delete="delete"><nc:name>192.168.47.0/24</nc:name></nc:route></nc:static><nc:static><nc:route><nc:name>192.168.47.0/24</nc:name><nc:next-hop>10.200.16.2</nc:next-hop></nc:route></nc:static></nc:routing-options>
#   - '<nc:routing-instances xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0"/>'
# after:
#   - address_families:
#       - afi: ipv4
#         routes:
#           - dest: 192.168.16.0/24
#             next_hop:
#               - forward_router_address: 172.16.1.2
#           - dest: 192.168.47.0/24
#             next_hop:
#               - forward_router_address: 10.200.16.2

# After state:
# ------------
#
# admin# show routing-options
# static {
#     route 192.168.47.0/24 next-hop 10.200.16.2;
#     route 192.168.16.0/24 next-hop 172.16.1.2;
# }

# Using gathered to gather static route facts from the device
# Before state
# ------------
# admin# show routing-options
# static {
#     route 192.168.16.0/24 next-hop 172.16.1.2;
#     route 192.168.47.0/24 next-hop 10.200.16.2;
# }
- name: Gather static routes facts from the device using junos_static_routes module
  junipernetworks.junos.junos_static_routes:
    state: gathered

# Task output:
# ------------
# gathered:
#   - address_families:
#       - afi: ipv4
#         routes:
#           - dest: 192.168.16.0/24
#             next_hop:
#               - forward_router_address: 172.16.1.2
#           - dest: 192.168.47.0/24
#             next_hop:
#               - forward_router_address: 10.200.16.2

# Using rendered

- name: Render platform specific commands (without connecting to the device)
  junipernetworks.junos.junos_static_routes:
    config:
      - address_families:
          - afi: ipv4
            routes:
              - dest: 192.168.16.0/24
                next_hop:
                  - forward_router_address: 172.16.1.2
    state: rendered

# Task output:
# ------------
# rendered:
#   - '<nc:routing-options
#     xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0"><nc:static><nc:route><nc:name>192.168.16.0/24</nc:name>
#     <nc:next-hop>172.16.1.2</nc:next-hop></nc:route></nc:static></nc:routing-options>'

# Using parsed

# parsed.cfg
# ------------
# <?xml version="1.0" encoding="UTF-8"?>
# <rpc-reply message-id="urn:uuid:0cadb4e8-5bba-47f4-986e-72906227007f">
#     <configuration changed-seconds="1590139550" changed-localtime="2020-05-22 09:25:50 UTC">
#         <version>18.4R1-S2.4</version>
#         <routing-options>
#         <static>
#             <route>
#                 <name>192.168.16.0/24</name>
#                 <next-hop>172.16.1.2</next-hop>
#                 <next-hop>172.16.1.3</next-hop>
#             </route>
#             <route>
#                 <name>192.168.47.0/24</name>
#                 <next-hop>10.200.16.2</next-hop>
#             </route>
#         </static>
#     </routing-options>
#     </configuration>
# </rpc-reply>

- name: Parsed running config (without connecting to the device)
  junipernetworks.junos.junos_static_routes:
    running_config: "{{ lookup('file', 'parsed.cfg') }}"
    state: parsed

# Task output:
# ------------
# parsed:
#   - address_families:
#       - afi: ipv4
#         routes:
#           - dest: 192.168.16.0/24
#             next_hop:
#               - forward_router_address: '[''172.16.1.2'', ''172.16.1.3'']'
#           - dest: 192.168.47.0/24
#             next_hop:
#               - forward_router_address: 10.200.16.2

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

Key Returned Description
after
string
when changed
The resulting configuration model invocation.

Sample:
The configuration returned will always be in the same format of the parameters above.
before
string
always
The configuration prior to the model invocation.

Sample:
The configuration returned will always be in the same format of the parameters above.
commands
list
always
The set of commands pushed to the remote device.

Sample:
['command 1', 'command 2', 'command 3']
gathered
list
when state is gathered
Facts about the network resource gathered from the remote device as structured data.

Sample:
This output will always be in the same format as the module argspec.
parsed
list
when state is parsed
The device native config provided in running_config option parsed into structured data as per module argspec.

Sample:
This output will always be in the same format as the module argspec.
rendered
list
when state is rendered
The provided configuration in the task rendered in device-native format (offline).

Sample:
['<nc:protocols xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0">']


Authors

  • Daniel Mellado (@dmellado)