junipernetworks.junos.junos_prefix_lists module – Manage prefix-lists attributes of interfaces on Junos devices.
Note
This module is part of the junipernetworks.junos collection (version 2.10.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 junipernetworks.junos
.
To use it in a playbook, specify: junipernetworks.junos.junos_prefix_lists
.
New in version 2.1.0: of junipernetworks.junos
Synopsis
Manage prefix-lists attributes of interfaces on Junos network devices.
Note
This module has a corresponding action plugin.
Requirements
The below requirements are needed on the host that executes this module.
ncclient (>=v0.6.4)
xmltodict (>=0.12.0)
Parameters
Parameter |
Comments |
---|---|
The provided link BGP address family dictionary. |
|
Specify address prefixes. |
|
Enable object to exist in dynamic DB. Choices:
|
|
Specify the name of the prefix-list. |
|
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 policy-options. The state parsed reads the configuration from |
|
The state the configuration should be left in. Choices:
|
Notes
Note
This module requires the netconf system service be enabled on the device being managed.
This module works with connection
netconf
.Tested against JunOS v18.4R1
Examples
# Using merged
#
# Before state
# ------------
#
# vagrant@vsrx# show policy-options
#
# [edit]
- name: Merge Junos prefix lists
junipernetworks.junos.junos_prefix_lists:
config:
- name: Internal
address_prefixes:
- 172.16.1.32
- 172.16.3.32
- name: Test1
dynamic_db: true
- name: Test2
address_prefixes:
- 172.16.2.32
- 172.16.7.32
- 172.16.9.32
state: merged
#
# -------------------------
# Module Execution Result
# -------------------------
#
# "before": []
# "commands": [
# "<nc:policy-options xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0">
# "<nc:prefix-list><nc:name>Internal</nc:name><nc:prefix-list-item><nc:name>172.16.1.32</nc:name>"
# "</nc:prefix-list-item><nc:prefix-list-item><nc:name>172.16.3.32</nc:name>"
# "</nc:prefix-list-item></nc:prefix-list><nc:prefix-list><nc:name>Test1</nc:name>"
# "<nc:dynamic-db/></nc:prefix-list><nc:prefix-list><nc:name>Test2</nc:name>"
# "<nc:prefix-list-item><nc:name>172.16.2.32</nc:name></nc:prefix-list-item>"
# "<nc:prefix-list-item><nc:name>172.16.7.32</nc:name></nc:prefix-list-item>"
# "<nc:prefix-list-item><nc:name>172.16.9.32</nc:name></nc:prefix-list-item>"
# "</nc:prefix-list></nc:policy-options>"
# ]
#
# "after": [
# {
# "address_prefixes": [
# "172.16.1.32/32",
# "172.16.3.32/32"
# ],
# "name": "Internal"
# },
# {
# "dynamic_db": true,
# "name": "Test1"
# },
# {
# "address_prefixes": [
# "172.16.2.32/32",
# "172.16.7.32/32",
# "172.16.9.32/32"
# ],
# "name": "Test2"
# }
# ]
# After state
# -----------
#
# vagrant@vsrx# show policy-options
# prefix-list Internal {
# 172.16.1.32/32;
# 172.16.3.32/32;
# }
# prefix-list Test1 {
# dynamic-db;
# }
# prefix-list Test2 {
# 172.16.2.32/32;
# 172.16.7.32/32;
# 172.16.9.32/32;
# }
#
# Using gathered
#
# Before state
# ------------
#
# vagrant@vsrx# show policy-options
# prefix-list Internal {
# 172.16.1.32/32;
# 172.16.3.32/32;
# }
# prefix-list Test1 {
# dynamic-db;
# }
# prefix-list Test2 {
# 172.16.2.32/32;
# 172.16.7.32/32;
# 172.16.9.32/32;
# }
- name: Gather Junos prefix-lists
junipernetworks.junos.junos_prefix_lists:
state: gathered
#
#
# -------------------------
# Module Execution Result
# -------------------------
#
# "gathered": [
# {
# "address_prefixes": [
# "172.16.1.32/32",
# "172.16.3.32/32"
# ],
# "name": "Internal"
# },
# {
# "dynamic_db": true,
# "name": "Test1"
# },
# {
# "address_prefixes": [
# "172.16.2.32/32",
# "172.16.7.32/32",
# "172.16.9.32/32"
# ],
# "name": "Test2"
# }
# ]
#
# Using replaced
#
# Before state
# ------------
#
# vagrant@vsrx# show policy-options
# prefix-list Internal {
# 172.16.1.32/32;
# 172.16.3.32/32;
# }
# prefix-list Test1 {
# dynamic-db;
# }
# prefix-list Test2 {
# 172.16.2.32/32;
# 172.16.7.32/32;
# 172.16.9.32/32;
# }
- name: Replace existing Junos prefix-lists configuration with provided config
junipernetworks.junos.junos_prefix_lists:
config:
- name: Test2
address_prefixes:
- 172.16.4.32
- 172.16.8.32
- 172.16.9.32"
state: replaced
# -------------------------
# Module Execution Result
# -------------------------
#
# "before": [
# {
# "address_prefixes": [
# "172.16.1.32/32",
# "172.16.3.32/32"
# ],
# "name": "Internal"
# },
# {
# "dynamic_db": true,
# "name": "Test1"
# },
# {
# "address_prefixes": [
# "172.16.2.32/32",
# "172.16.7.32/32",
# "172.16.9.32/32"
# ],
# "name": "Test2"
# }
# ]
# "commands": [
# "<nc:policy-options xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0">
# "<nc:prefix-list delete="delete"><nc:name>Test2</nc:name></nc:prefix-list>"
# "<nc:prefix-list><nc:name>Test2</nc:name><nc:prefix-list-item><nc:name>172.16.4.32</nc:name>"
# "</nc:prefix-list-item><nc:prefix-list-item><nc:name>172.16.8.32</nc:name>"
# "</nc:prefix-list-item><nc:prefix-list-item><nc:name>172.16.9.32</nc:name>"
# "</nc:prefix-list-item></nc:prefix-list></nc:policy-options>"
# ]
#
# "after": [
# {
# "address_prefixes": [
# "172.16.1.32/32",
# "172.16.3.32/32"
# ],
# "name": "Internal"
# },
# {
# "dynamic_db": true,
# "name": "Test1"
# },
# {
# "address_prefixes": [
# "172.16.4.32/32",
# "172.16.8.32/32",
# "172.16.9.32/32"
# ],
# "name": "Test2"
# }
# ]
# After state
# -----------
#
# vagrant@vsrx# show policy-options
# prefix-list Internal {
# 172.16.1.32/32;
# 172.16.3.32/32;
# }
# prefix-list Test1 {
# dynamic-db;
# }
# prefix-list Test2 {
# 172.16.4.32/32;
# 172.16.8.32/32;
# 172.16.9.32/32;
# }
# Using overridden
#
# Before state
# ------------
#
# vagrant@vsrx# show policy-options
# prefix-list Internal {
# 172.16.1.32/32;
# 172.16.3.32/32;
# }
# prefix-list Test1 {
# dynamic-db;
# }
# prefix-list Test2 {
# 172.16.4.32/32;
# 172.16.8.32/32;
# 172.16.9.32/32;
# }
- name: Override Junos prefix-lists configuration with provided configuration
junipernetworks.junos.junos_prefix_lists:
config:
- name: Test2
address_prefixes:
- 172.16.4.32/28
- 172.16.8.32/28
- 172.16.9.32/28
state: overridden
# -------------------------
# Module Execution Result
# -------------------------
#
# "before": [
# {
# "address_prefixes": [
# "172.16.1.32/32",
# "172.16.3.32/32"
# ],
# "name": "Internal"
# },
# {
# "dynamic_db": true,
# "name": "Test1"
# },
# {
# "address_prefixes": [
# "172.16.4.32/32",
# "172.16.8.32/32",
# "172.16.9.32/32"
# ],
# "name": "Test2"
# }
# ]
# "commands": [
# "<nc:policy-options xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0">
# "<nc:prefix-list delete="delete"><nc:name>Internal</nc:name>"
# "</nc:prefix-list><nc:prefix-list delete="delete"><nc:name>Test1</nc:name>"
# "</nc:prefix-list><nc:prefix-list delete="delete"><nc:name>Test2</nc:name>"
# "</nc:prefix-list><nc:prefix-list><nc:name>Test2</nc:name><nc:prefix-list-item>"
# "<nc:name>172.16.4.32/28</nc:name></nc:prefix-list-item><nc:prefix-list-item>"
# "<nc:name>172.16.8.32/28</nc:name></nc:prefix-list-item><nc:prefix-list-item>"
# "<nc:name>172.16.9.32/28</nc:name></nc:prefix-list-item></nc:prefix-list></nc:policy-options>"
# ]
#
# "after": [
# {
# "address_prefixes": [
# "172.16.4.32/28",
# "172.16.8.32/28",
# "172.16.9.32/28"
# ],
# "name": "Test2"
# }
# ]
# After state
# -----------
#
# vagrant@vsrx# show policy-options
# prefix-list Test2 {
# 172.16.4.32/28;
# 172.16.8.32/28;
# 172.16.9.32/28;
# }
# Using deleted
#
# Before state
# ------------
#
# vagrant@vsrx# show policy-options
# prefix-list Internal {
# 172.16.1.32/32;
# 172.16.3.32/32;
# }
# prefix-list Test1 {
# dynamic-db;
# }
# prefix-list Test2 {
# 172.16.2.32/32;
# 172.16.7.32/32;
# 172.16.9.32/32;
# }
- name: Delete provided prefix-lists
junipernetworks.junos.junos_prefix_lists:
config:
- name: "Test1"
- name: "Test2"
state: deleted
# ------------------------
# Module Execution Results
# ------------------------
#
# "before": [
# {
# "address_prefixes": [
# "172.16.1.32/32",
# "172.16.3.32/32"
# ],
# "name": "Internal"
# },
# {
# "dynamic_db": true,
# "name": "Test1"
# },
# {
# "address_prefixes": [
# "172.16.2.32/32",
# "172.16.7.32/32",
# "172.16.9.32/32"
# ],
# "name": "Test2"
# }
# ]
# "commands": [
# "<nc:policy-options xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0">
# "<nc:prefix-list delete="delete"><nc:name>Test1</nc:name></nc:prefix-list>"
# "<nc:prefix-list delete="delete"><nc:name>Test2</nc:name></nc:prefix-list></nc:policy-options>"
# ]
#
# "after": [
# {
# "address_prefixes": [
# "172.16.1.32/32",
# "172.16.3.32/32"
# ],
# "name": "Internal"
# }
# ]
# After state
# -----------
#
# vagrant@vsrx# show policy-options
# prefix-list Internal {
# 172.16.1.32/32;
# 172.16.3.32/32;
# }
#
# Using deleted without specifying config
#
# Before state
# ------------
#
# vagrant@vsrx# show policy-options
# prefix-list Internal {
# 172.16.1.32/32;
# 172.16.3.32/32;
# }
# prefix-list Test1 {
# dynamic-db;
# }
# prefix-list Test2 {
# 172.16.2.32/32;
# 172.16.7.32/32;
# 172.16.9.32/32;
# }
- name: Delete complete Junos prefix-lists configuration
junipernetworks.junos.junos_prefix_lists:
state: deleted
# ------------------------
# Module Execution Results
# ------------------------
#
# "before": [
# {
# "address_prefixes": [
# "172.16.1.32/32",
# "172.16.3.32/32"
# ],
# "name": "Internal"
# },
# {
# "dynamic_db": true,
# "name": "Test1"
# },
# {
# "address_prefixes": [
# "172.16.2.32/32",
# "172.16.7.32/32",
# "172.16.9.32/32"
# ],
# "name": "Test2"
# }
# ]
# "commands": ["<nc:policy-options xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0">
# "<nc:prefix-list delete="delete"/></nc:policy-options>"
# ]
#
# "after": []
# After state
# -----------
#
# vagrant@vsrx# show policy-options
#
# [edit]
#
# 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>
# <policy-options>
# <prefix-list>
# <name>64510</name>
# </prefix-list>
# <prefix-list>
# <name>64500</name>
# <dynamic-db/>
# <prefix-list-item>
# <name>172.16.1.16/28</name>
# </prefix-list-item>
# <prefix-list-item>
# <name>172.16.1.32/28</name>
# </prefix-list-item>
# </prefix-list>
# </policy-options>
# </configuration>
# </rpc-reply>
- name: Parse running prefix-lists configuration
junipernetworks.junos.junos_prefix_lists:
running_config: "{{ lookup('file', './parsed.cfg') }}"
state: parsed
#
#
# -------------------------
# Module Execution Result
# -------------------------
#
#
# "parsed": [
# {
# "name": "64510"
# },
# {
# "address_prefixes": [
# "172.16.1.16/28",
# "172.16.1.32/28"
# ],
# "dynamic_db": true,
# "name": "64500"
# }
# ]
#
#
# Using rendered
#
- name: Render the xml for provided configuration
junipernetworks.junos.junos_prefix_lists:
config:
- name: Internal
address_prefixes:
- 172.16.1.32
- 172.16.3.32
- name: Test1
dynamic_db: true
- name: Test2
address_prefixes:
- 172.16.2.32
- 172.16.7.32
- 172.16.9.32
state: rendered
#
#
# -------------------------
# Module Execution Result
# -------------------------
#
#
# "rendered": "<nc:policy-options xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0">
# "<nc:prefix-list><nc:name>Internal</nc:name><nc:prefix-list-item><nc:name>172.16.1.32</nc:name>"
# "</nc:prefix-list-item><nc:prefix-list-item><nc:name>172.16.3.32</nc:name></nc:prefix-list-item>"
# "</nc:prefix-list><nc:prefix-list><nc:name>Test1</nc:name><nc:dynamic-db/></nc:prefix-list>"
# "<nc:prefix-list><nc:name>Test2</nc:name><nc:prefix-list-item><nc:name>172.16.2.32</nc:name>"
# "</nc:prefix-list-item><nc:prefix-list-item><nc:name>172.16.7.32</nc:name></nc:prefix-list-item>"
# "<nc:prefix-list-item><nc:name>172.16.9.32</nc:name></nc:prefix-list-item>"
# "</nc:prefix-list></nc:policy-options>"
Return Values
Common return values are documented here, the following are the fields unique to this module:
Key |
Description |
---|---|
The resulting configuration model invocation. Returned: when changed Sample: “The configuration returned will always be in the same format\n of the parameters above.\n” |
|
The configuration prior to the model invocation. Returned: always Sample: “The configuration returned will always be in the same format\n of the parameters above.\n” |
|
The set of commands pushed to the remote device. Returned: always Sample: [“\u003cnc:policy-options xmlns:nc=\”urn:ietf:params:xml:ns:netconf:base:1.0\”\u003e \”\u003cnc:prefix-list delete=\”delete\”/\u003e\u003c/nc:policy-options\u003e\””, “xml 2”, “command 3”] |
Authors
Rohit Thakur (@rohitthakur2590)