Add common aggregate arguments for junos modules (#28124)

If parameter value in aggregate is not set, fetch it's corresponding
value from top level parameters.
This commit is contained in:
Ganesh Nalawade 2017-08-14 10:17:03 +05:30 committed by GitHub
parent d78c199972
commit 711a6b2326
25 changed files with 374 additions and 272 deletions

View file

@ -329,6 +329,12 @@ def ternary(value, true_val, false_val):
return false_val return false_val
def remove_default_spec(spec):
for item in spec:
if 'default' in spec[item]:
del spec[item]['default']
class Template: class Template:
def __init__(self): def __init__(self):

View file

@ -52,7 +52,7 @@ requirements:
- ncclient (>=v0.5.2) - ncclient (>=v0.5.2)
notes: notes:
- This module requires the netconf system service be enabled on - This module requires the netconf system service be enabled on
the remote device being managed the remote device being managed.
""" """
EXAMPLES = """ EXAMPLES = """

View file

@ -72,7 +72,7 @@ requirements:
- ncclient (>=v0.5.2) - ncclient (>=v0.5.2)
notes: notes:
- This module requires the netconf system service be enabled on - This module requires the netconf system service be enabled on
the remote device being managed the remote device being managed.
""" """
EXAMPLES = """ EXAMPLES = """
@ -119,14 +119,20 @@ EXAMPLES = """
- name: Create interface using aggregate - name: Create interface using aggregate
junos_interface: junos_interface:
aggregate: aggregate:
- { name: ge-0/0/1, description: test-interface-1, speed: 1g, duplex: half, mtu: 512} - name: ge-0/0/1
- { name: ge-0/0/2, description: test-interface-2, speed: 10m, duplex: full, mtu: 256} description: test-interface-1
- name: ge-0/0/2
description: test-interface-2
speed: 1g
duplex: full
mtu: 512
- name: Delete interface using aggregate - name: Delete interface using aggregate
junos_interface: junos_interface:
aggregate: aggregate:
- { name: ge-0/0/1, description: test-interface-1, state: absent} - name: ge-0/0/1
- { name: ge-0/0/2, description: test-interface-2, state: absent} - name: ge-0/0/2
state: absent
- name: Check intent arguments - name: Check intent arguments
junos_interface: junos_interface:
@ -155,10 +161,12 @@ diff.prepared:
""" """
import collections import collections
from copy import deepcopy
from time import sleep from time import sleep
from ansible.module_utils.basic import AnsibleModule from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.netconf import send_request from ansible.module_utils.netconf import send_request
from ansible.module_utils.network_common import remove_default_spec
from ansible.module_utils.network_common import conditional from ansible.module_utils.network_common import conditional
from ansible.module_utils.junos import junos_argument_spec, check_args from ansible.module_utils.junos import junos_argument_spec, check_args
from ansible.module_utils.junos import load_config, map_params_to_obj, map_obj_to_ele from ansible.module_utils.junos import load_config, map_params_to_obj, map_obj_to_ele
@ -200,14 +208,16 @@ def main():
tx_rate=dict(), tx_rate=dict(),
rx_rate=dict(), rx_rate=dict(),
delay=dict(default=10, type='int'), delay=dict(default=10, type='int'),
state=dict(default='present', state=dict(default='present', choices=['present', 'absent', 'up', 'down']),
choices=['present', 'absent', 'up', 'down']),
active=dict(default=True, type='bool') active=dict(default=True, type='bool')
) )
aggregate_spec = element_spec.copy() aggregate_spec = deepcopy(element_spec)
aggregate_spec['name'] = dict(required=True) aggregate_spec['name'] = dict(required=True)
# remove default in aggregate spec, to handle common arguments
remove_default_spec(aggregate_spec)
argument_spec = dict( argument_spec = dict(
aggregate=dict(type='list', elements='dict', options=aggregate_spec), aggregate=dict(type='list', elements='dict', options=aggregate_spec),
) )
@ -216,9 +226,7 @@ def main():
argument_spec.update(junos_argument_spec) argument_spec.update(junos_argument_spec)
required_one_of = [['name', 'aggregate']] required_one_of = [['name', 'aggregate']]
mutually_exclusive = [['name', 'aggregate'], mutually_exclusive = [['name', 'aggregate']]
['state', 'aggregate'],
['active', 'aggregate']]
module = AnsibleModule(argument_spec=argument_spec, module = AnsibleModule(argument_spec=argument_spec,
required_one_of=required_one_of, required_one_of=required_one_of,
@ -253,6 +261,11 @@ def main():
requests = list() requests = list()
for param in params: for param in params:
# if key doesn't exist in the item, get it from module.params
for key in param:
if param.get(key) is None:
param[key] = module.params[key]
item = param.copy() item = param.copy()
state = item.get('state') state = item.get('state')
item['disable'] = True if not item.get('enabled') else False item['disable'] = True if not item.get('enabled') else False

View file

@ -38,10 +38,6 @@ options:
default: 0 default: 0
aggregate: aggregate:
description: List of L3 interfaces definitions description: List of L3 interfaces definitions
purge:
description:
- Purge L3 interfaces not defined in the aggregate parameter.
default: no
state: state:
description: description:
- State of the L3 interface configuration. - State of the L3 interface configuration.
@ -56,7 +52,7 @@ requirements:
- ncclient (>=v0.5.2) - ncclient (>=v0.5.2)
notes: notes:
- This module requires the netconf system service be enabled on - This module requires the netconf system service be enabled on
the remote device being managed the remote device being managed.
""" """
EXAMPLES = """ EXAMPLES = """
@ -84,10 +80,9 @@ EXAMPLES = """
aggregate: aggregate:
- name: ge-0/0/1 - name: ge-0/0/1
ipv4: 1.1.1.1 ipv4: 1.1.1.1
state: absent
- name: ge-0/0/2 - name: ge-0/0/2
ipv4: 2.2.2.2 ipv4: 2.2.2.2
state: absent state: absent
""" """
RETURN = """ RETURN = """
@ -103,7 +98,10 @@ diff:
""" """
import collections import collections
from copy import deepcopy
from ansible.module_utils.basic import AnsibleModule from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.network_common import remove_default_spec
from ansible.module_utils.junos import junos_argument_spec, check_args from ansible.module_utils.junos import junos_argument_spec, check_args
from ansible.module_utils.junos import load_config, map_params_to_obj, map_obj_to_ele from ansible.module_utils.junos import load_config, map_params_to_obj, map_obj_to_ele
from ansible.module_utils.junos import commit_configuration, discard_changes, locked_config, to_param_list from ansible.module_utils.junos import commit_configuration, discard_changes, locked_config, to_param_list
@ -128,22 +126,21 @@ def main():
active=dict(default=True, type='bool') active=dict(default=True, type='bool')
) )
aggregate_spec = element_spec.copy() aggregate_spec = deepcopy(element_spec)
aggregate_spec['name'] = dict(required=True) aggregate_spec['name'] = dict(required=True)
# remove default in aggregate spec, to handle common arguments
remove_default_spec(aggregate_spec)
argument_spec = dict( argument_spec = dict(
aggregate=dict(type='list', elements='dict', options=aggregate_spec), aggregate=dict(type='list', elements='dict', options=aggregate_spec),
purge=dict(default=False, type='bool')
) )
argument_spec.update(element_spec) argument_spec.update(element_spec)
argument_spec.update(junos_argument_spec) argument_spec.update(junos_argument_spec)
required_one_of = [['name', 'aggregate']] required_one_of = [['name', 'aggregate']]
mutually_exclusive = [['name', 'aggregate']]
mutually_exclusive = [['name', 'aggregate'],
['state', 'aggregate'],
['active', 'aggregate']]
module = AnsibleModule(argument_spec=argument_spec, module = AnsibleModule(argument_spec=argument_spec,
supports_check_mode=True, supports_check_mode=True,
@ -172,6 +169,11 @@ def main():
requests = list() requests = list()
for param in params: for param in params:
# if key doesn't exist in the item, get it from module.params
for key in param:
if param.get(key) is None:
param[key] = module.params[key]
item = param.copy() item = param.copy()
if not item['ipv4'] and not item['ipv6']: if not item['ipv4'] and not item['ipv6']:
module.fail_json(msg="one of the following is required: ipv4,ipv6") module.fail_json(msg="one of the following is required: ipv4,ipv6")

View file

@ -53,10 +53,6 @@ options:
- Description of Interface. - Description of Interface.
aggregate: aggregate:
description: List of link aggregation definitions. description: List of link aggregation definitions.
purge:
description:
- Purge link aggregation groups not defined in the aggregates parameter.
default: no
state: state:
description: description:
- State of the link aggregation group. - State of the link aggregation group.
@ -71,7 +67,7 @@ requirements:
- ncclient (>=v0.5.2) - ncclient (>=v0.5.2)
notes: notes:
- This module requires the netconf system service be enabled on - This module requires the netconf system service be enabled on
the remote device being managed the remote device being managed.
""" """
EXAMPLES = """ EXAMPLES = """
@ -160,7 +156,10 @@ diff:
""" """
import collections import collections
from copy import deepcopy
from ansible.module_utils.basic import AnsibleModule from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.network_common import remove_default_spec
from ansible.module_utils.junos import junos_argument_spec, check_args from ansible.module_utils.junos import junos_argument_spec, check_args
from ansible.module_utils.junos import load_config, map_params_to_obj, map_obj_to_ele, to_param_list from ansible.module_utils.junos import load_config, map_params_to_obj, map_obj_to_ele, to_param_list
from ansible.module_utils.junos import commit_configuration, discard_changes, locked_config, get_configuration from ansible.module_utils.junos import commit_configuration, discard_changes, locked_config, get_configuration
@ -260,7 +259,7 @@ def main():
""" """
element_spec = dict( element_spec = dict(
name=dict(), name=dict(),
mode=dict(default='on', type='str', choices=['on', 'off', 'active', 'passive']), mode=dict(default='on', choices=['on', 'off', 'active', 'passive']),
members=dict(type='list'), members=dict(type='list'),
min_links=dict(type='int'), min_links=dict(type='int'),
device_count=dict(type='int'), device_count=dict(type='int'),
@ -269,27 +268,21 @@ def main():
active=dict(default=True, type='bool') active=dict(default=True, type='bool')
) )
aggregate_spec = element_spec.copy() aggregate_spec = deepcopy(element_spec)
aggregate_spec['name'] = dict(required=True) aggregate_spec['name'] = dict(required=True)
# remove default in aggregate spec, to handle common arguments
remove_default_spec(aggregate_spec)
argument_spec = dict( argument_spec = dict(
aggregate=dict(type='list', elements='dict', options=aggregate_spec), aggregate=dict(type='list', elements='dict', options=aggregate_spec),
purge=dict(default=False, type='bool')
) )
argument_spec.update(element_spec) argument_spec.update(element_spec)
argument_spec.update(junos_argument_spec) argument_spec.update(junos_argument_spec)
required_one_of = [['name', 'aggregate']] required_one_of = [['name', 'aggregate']]
mutually_exclusive = [['name', 'aggregate']]
mutually_exclusive = [['name', 'aggregate'],
['mode', 'aggregate'],
['members', 'aggregate'],
['min_links', 'aggregate'],
['device_count', 'aggregate'],
['description', 'aggregate'],
['state', 'aggregate'],
['active', 'aggregate']]
module = AnsibleModule(argument_spec=argument_spec, module = AnsibleModule(argument_spec=argument_spec,
supports_check_mode=True, supports_check_mode=True,
@ -307,8 +300,12 @@ def main():
params = to_param_list(module) params = to_param_list(module)
requests = list() requests = list()
for param in params: for param in params:
item = param.copy() # if key doesn't exist in the item, get it from module.params
for key in param:
if param.get(key) is None:
param[key] = module.params[key]
item = param.copy()
state = item.get('state') state = item.get('state')
item['disable'] = True if state == 'down' else False item['disable'] = True if state == 'down' else False

View file

@ -60,7 +60,7 @@ requirements:
- ncclient (>=v0.5.2) - ncclient (>=v0.5.2)
notes: notes:
- This module requires the netconf system service be enabled on - This module requires the netconf system service be enabled on
the remote device being managed the remote device being managed.
""" """
EXAMPLES = """ EXAMPLES = """

View file

@ -49,7 +49,7 @@ requirements:
- ncclient (>=v0.5.2) - ncclient (>=v0.5.2)
notes: notes:
- This module requires the netconf system service be enabled on - This module requires the netconf system service be enabled on
the remote device being managed the remote device being managed.
""" """
EXAMPLES = """ EXAMPLES = """

View file

@ -40,10 +40,6 @@ options:
- Set logging severity levels. - Set logging severity levels.
aggregate: aggregate:
description: List of logging definitions. description: List of logging definitions.
purge:
description:
- Purge logging not defined in the aggregate parameter.
default: no
state: state:
description: description:
- State of the logging configuration. - State of the logging configuration.
@ -71,6 +67,11 @@ options:
- Number of files to be archived, this is applicable if value - Number of files to be archived, this is applicable if value
of I(dest) is C(file). The acceptable value is in range from 1 to 1000. of I(dest) is C(file). The acceptable value is in range from 1 to 1000.
required: false required: false
requirements:
- ncclient (>=v0.5.2)
notes:
- This module requires the netconf system service be enabled on
the remote device being managed.
""" """
EXAMPLES = """ EXAMPLES = """
@ -100,15 +101,22 @@ EXAMPLES = """
- name: Configure file logging using aggregate - name: Configure file logging using aggregate
junos_logging: junos_logging:
dest: file
aggregate: aggregate:
- {dest: file, name: test-1, facility: pfe, level: critical, active: True} - name: test-1
- {dest: file, name: test-2, facility: kernel, level: emergency, active: True} facility: pfe
level: critical
- name: test-2
facility: kernel
level: emergency
active: True
- name: Delete file logging using aggregate - name: Delete file logging using aggregate
junos_logging: junos_logging:
aggregate: aggregate:
- {dest: file, name: test-1, facility: pfe, level: critical, active: True, state: absent} - { dest: file, name: test-1, facility: pfe, level: critical }
- {dest: file, name: test-2, facility: kernel, level: emergency, active: True, state: absent} - { dest: file, name: test-2, facility: kernel, level: emergency }
state: absent
""" """
RETURN = """ RETURN = """
@ -126,7 +134,10 @@ diff.prepared:
""" """
import collections import collections
from copy import deepcopy
from ansible.module_utils.basic import AnsibleModule from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.network_common import remove_default_spec
from ansible.module_utils.junos import junos_argument_spec, check_args from ansible.module_utils.junos import junos_argument_spec, check_args
from ansible.module_utils.junos import load_config, map_params_to_obj, map_obj_to_ele, to_param_list from ansible.module_utils.junos import load_config, map_params_to_obj, map_obj_to_ele, to_param_list
from ansible.module_utils.junos import commit_configuration, discard_changes, locked_config from ansible.module_utils.junos import commit_configuration, discard_changes, locked_config
@ -180,24 +191,18 @@ def main():
active=dict(default=True, type='bool') active=dict(default=True, type='bool')
) )
aggregate_spec = deepcopy(element_spec)
# remove default in aggregate spec, to handle common arguments
remove_default_spec(aggregate_spec)
argument_spec = dict( argument_spec = dict(
aggregate=dict(type='list', elements='dict', options=element_spec), aggregate=dict(type='list', elements='dict', options=aggregate_spec),
purge=dict(default=False, type='bool')
) )
argument_spec.update(element_spec) argument_spec.update(element_spec)
argument_spec.update(junos_argument_spec) argument_spec.update(junos_argument_spec)
mutually_exclusive = [['dest', 'aggregate'],
['name', 'aggregate'],
['facility', 'aggregate'],
['rotate_frequency', 'aggregate'],
['size', 'aggregate'],
['files', 'aggregate'],
['src_addr', 'aggregate'],
['state', 'aggregate'],
['active', 'aggregate']]
required_if = [('dest', 'host', ['name', 'facility', 'level']), required_if = [('dest', 'host', ['name', 'facility', 'level']),
('dest', 'file', ['name', 'facility', 'level']), ('dest', 'file', ['name', 'facility', 'level']),
('dest', 'user', ['name', 'facility', 'level']), ('dest', 'user', ['name', 'facility', 'level']),
@ -205,7 +210,6 @@ def main():
module = AnsibleModule(argument_spec=argument_spec, module = AnsibleModule(argument_spec=argument_spec,
required_if=required_if, required_if=required_if,
mutually_exclusive=mutually_exclusive,
supports_check_mode=True) supports_check_mode=True)
warnings = list() warnings = list()
@ -220,6 +224,13 @@ def main():
requests = list() requests = list()
for param in params: for param in params:
# if key doesn't exist in the item, get it from module.params
for key in param:
if param.get(key) is None:
param[key] = module.params[key]
module._check_required_if(required_if, param)
item = param.copy() item = param.copy()
dest = item.get('dest') dest = item.get('dest')
if dest == 'console' and item.get('name'): if dest == 'console' and item.get('name'):

View file

@ -45,10 +45,6 @@ options:
- Assign preference for qualified next hop. - Assign preference for qualified next hop.
aggregate: aggregate:
description: List of static route definitions description: List of static route definitions
purge:
description:
- Purge static routes not defined in the aggregate parameter.
default: no
state: state:
description: description:
- State of the static route configuration. - State of the static route configuration.
@ -63,7 +59,7 @@ requirements:
- ncclient (>=v0.5.2) - ncclient (>=v0.5.2)
notes: notes:
- This module requires the netconf system service be enabled on - This module requires the netconf system service be enabled on
the remote device being managed the remote device being managed.
""" """
EXAMPLES = """ EXAMPLES = """
@ -104,14 +100,16 @@ EXAMPLES = """
- name: Configure static route using aggregate - name: Configure static route using aggregate
junos_static_route: junos_static_route:
aggregate: aggregate:
- {address: 4.4.4.0/24, next_hop: 3.3.3.3, preference: 10, qualified_next_hop: 5.5.5.5, qualified_preference: 30} - { address: 4.4.4.0/24, next_hop: 3.3.3.3, qualified_next_hop: 5.5.5.5, qualified_preference: 30 }
- {address: 5.5.5.0/24, next_hop: 6.6.6.6, preference: 11, qualified_next_hop: 7.7.7.7, qualified_preference: 12} - { address: 5.5.5.0/24, next_hop: 6.6.6.6, qualified_next_hop: 7.7.7.7, qualified_preference: 12 }
preference: 10
- name: Delete static route using aggregate - name: Delete static route using aggregate
junos_static_route: junos_static_route:
aggregate: aggregate:
- {address: 4.4.4.0/24, state: absent} - address: 4.4.4.0/24
- {address: 5.5.5.0/24, state: absent} - address: 5.5.5.0/24
state: absent
""" """
RETURN = """ RETURN = """
@ -132,7 +130,10 @@ diff.prepared:
""" """
import collections import collections
from copy import deepcopy
from ansible.module_utils.basic import AnsibleModule from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.network_common import remove_default_spec
from ansible.module_utils.junos import junos_argument_spec, check_args from ansible.module_utils.junos import junos_argument_spec, check_args
from ansible.module_utils.junos import load_config, map_params_to_obj, map_obj_to_ele, to_param_list from ansible.module_utils.junos import load_config, map_params_to_obj, map_obj_to_ele, to_param_list
from ansible.module_utils.junos import commit_configuration, discard_changes, locked_config from ansible.module_utils.junos import commit_configuration, discard_changes, locked_config
@ -149,8 +150,8 @@ def main():
""" main entry point for module execution """ main entry point for module execution
""" """
element_spec = dict( element_spec = dict(
address=dict(type='str', aliases=['prefix']), address=dict(aliases=['prefix']),
next_hop=dict(type='str'), next_hop=dict(),
preference=dict(type='int', aliases=['admin_distance']), preference=dict(type='int', aliases=['admin_distance']),
qualified_next_hop=dict(type='str'), qualified_next_hop=dict(type='str'),
qualified_preference=dict(type='int'), qualified_preference=dict(type='int'),
@ -158,9 +159,12 @@ def main():
active=dict(default=True, type='bool') active=dict(default=True, type='bool')
) )
aggregate_spec = element_spec.copy() aggregate_spec = deepcopy(element_spec)
aggregate_spec['address'] = dict(required=True) aggregate_spec['address'] = dict(required=True)
# remove default in aggregate spec, to handle common arguments
remove_default_spec(aggregate_spec)
argument_spec = dict( argument_spec = dict(
aggregate=dict(type='list', elements='dict', options=aggregate_spec), aggregate=dict(type='list', elements='dict', options=aggregate_spec),
purge=dict(default=False, type='bool') purge=dict(default=False, type='bool')
@ -170,13 +174,7 @@ def main():
argument_spec.update(junos_argument_spec) argument_spec.update(junos_argument_spec)
required_one_of = [['aggregate', 'address']] required_one_of = [['aggregate', 'address']]
mutually_exclusive = [['aggregate', 'address'], mutually_exclusive = [['aggregate', 'address']]
['aggregate', 'next_hop'],
['aggregate', 'preference'],
['aggregate', 'qualified_next_hop'],
['aggregate', 'qualified_preference'],
['aggregate', 'state'],
['aggregate', 'active']]
module = AnsibleModule(argument_spec=argument_spec, module = AnsibleModule(argument_spec=argument_spec,
required_one_of=required_one_of, required_one_of=required_one_of,
@ -206,6 +204,11 @@ def main():
requests = list() requests = list()
for param in params: for param in params:
# if key doesn't exist in the item, get it from module.params
for key in param:
if param.get(key) is None:
param[key] = module.params[key]
item = param.copy() item = param.copy()
if item['state'] == 'present': if item['state'] == 'present':
if not item['address'] and item['next_hop']: if not item['address'] and item['next_hop']:

View file

@ -64,7 +64,7 @@ requirements:
- ncclient (>=v0.5.2) - ncclient (>=v0.5.2)
notes: notes:
- This module requires the netconf system service be enabled on - This module requires the netconf system service be enabled on
the remote device being managed the remote device being managed.
""" """
EXAMPLES = """ EXAMPLES = """

View file

@ -94,7 +94,7 @@ requirements:
- ncclient (>=v0.5.2) - ncclient (>=v0.5.2)
notes: notes:
- This module requires the netconf system service be enabled on - This module requires the netconf system service be enabled on
the remote device being managed the remote device being managed.
""" """
EXAMPLES = """ EXAMPLES = """
@ -142,7 +142,10 @@ diff.prepared:
""" """
from functools import partial from functools import partial
from copy import deepcopy
from ansible.module_utils.basic import AnsibleModule from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.network_common import remove_default_spec
from ansible.module_utils.junos import junos_argument_spec, check_args from ansible.module_utils.junos import junos_argument_spec, check_args
from ansible.module_utils.junos import commit_configuration, discard_changes from ansible.module_utils.junos import commit_configuration, discard_changes
from ansible.module_utils.junos import load_config, locked_config from ansible.module_utils.junos import load_config, locked_config
@ -215,8 +218,6 @@ def map_params_to_obj(module):
if not aggregate: if not aggregate:
if not module.params['name'] and module.params['purge']: if not module.params['name'] and module.params['purge']:
return list() return list()
elif not module.params['name']:
module.fail_json(msg='missing required argument: name')
else: else:
collection = [{'name': module.params['name']}] collection = [{'name': module.params['name']}]
else: else:
@ -224,8 +225,6 @@ def map_params_to_obj(module):
for item in aggregate: for item in aggregate:
if not isinstance(item, dict): if not isinstance(item, dict):
collection.append({'username': item}) collection.append({'username': item})
elif 'name' not in item:
module.fail_json(msg='missing required argument: name')
else: else:
collection.append(item) collection.append(item)
@ -261,11 +260,17 @@ def main():
role=dict(choices=ROLES, default='unauthorized'), role=dict(choices=ROLES, default='unauthorized'),
sshkey=dict(), sshkey=dict(),
state=dict(choices=['present', 'absent'], default='present'), state=dict(choices=['present', 'absent'], default='present'),
active=dict(default=True, type='bool') active=dict(type='bool', default=True)
) )
aggregate_spec = deepcopy(element_spec)
aggregate_spec['name'] = dict(required=True)
# remove default in aggregate spec, to handle common arguments
remove_default_spec(aggregate_spec)
argument_spec = dict( argument_spec = dict(
aggregate=dict(type='list', elements='dict', options=element_spec, aliases=['collection', 'users']), aggregate=dict(type='list', elements='dict', options=aggregate_spec, aliases=['collection', 'users']),
purge=dict(default=False, type='bool') purge=dict(default=False, type='bool')
) )
@ -273,11 +278,7 @@ def main():
argument_spec.update(junos_argument_spec) argument_spec.update(junos_argument_spec)
required_one_of = [['aggregate', 'name']] required_one_of = [['aggregate', 'name']]
mutually_exclusive = [['aggregate', 'name'], mutually_exclusive = [['aggregate', 'name']]
['aggregate', 'full_name'],
['aggregate', 'sshkey'],
['aggregate', 'state'],
['aggregate', 'active']]
argument_spec.update(junos_argument_spec) argument_spec.update(junos_argument_spec)

View file

@ -39,10 +39,6 @@ options:
configured correctly. configured correctly.
aggregate: aggregate:
description: List of VLANs definitions. description: List of VLANs definitions.
purge:
description:
- Purge VLANs not defined in the aggregate parameter.
default: no
state: state:
description: description:
- State of the VLAN configuration. - State of the VLAN configuration.
@ -57,7 +53,7 @@ requirements:
- ncclient (>=v0.5.2) - ncclient (>=v0.5.2)
notes: notes:
- This module requires the netconf system service be enabled on - This module requires the netconf system service be enabled on
the remote device being managed the remote device being managed.
""" """
EXAMPLES = """ EXAMPLES = """
@ -87,14 +83,15 @@ EXAMPLES = """
- name: Create vlan configuration using aggregate - name: Create vlan configuration using aggregate
junos_vlan: junos_vlan:
aggregate: aggregate:
- { vlan_id: 159, name: test_vlan_1, description: test vlan-1, state: present } - { vlan_id: 159, name: test_vlan_1, description: test vlan-1 }
- { vlan_id: 160, name: test_vlan_2, description: test vlan-2, state: present } - { vlan_id: 160, name: test_vlan_2, description: test vlan-2 }
- name: Delete vlan configuration using aggregate - name: Delete vlan configuration using aggregate
junos_vlan: junos_vlan:
aggregate: aggregate:
- { vlan_id: 159, name: test_vlan_1, state: absent } - { vlan_id: 159, name: test_vlan_1 }
- { vlan_id: 160, name: test_vlan_2, state: absent } - { vlan_id: 160, name: test_vlan_2 }
state: absent
""" """
RETURN = """ RETURN = """
@ -110,7 +107,10 @@ diff.prepared:
""" """
import collections import collections
from copy import deepcopy
from ansible.module_utils.basic import AnsibleModule from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.network_common import remove_default_spec
from ansible.module_utils.junos import junos_argument_spec, check_args from ansible.module_utils.junos import junos_argument_spec, check_args
from ansible.module_utils.junos import load_config, map_params_to_obj, map_obj_to_ele, to_param_list from ansible.module_utils.junos import load_config, map_params_to_obj, map_obj_to_ele, to_param_list
from ansible.module_utils.junos import commit_configuration, discard_changes, locked_config from ansible.module_utils.junos import commit_configuration, discard_changes, locked_config
@ -149,26 +149,25 @@ def main():
state=dict(default='present', choices=['present', 'absent']), state=dict(default='present', choices=['present', 'absent']),
active=dict(default=True, type='bool') active=dict(default=True, type='bool')
) )
aggregate_spec = element_spec.copy()
aggregate_spec = deepcopy(element_spec)
aggregate_spec['name'] = dict(required=True) aggregate_spec['name'] = dict(required=True)
aggregate_spec['vlan_id'] = dict(required=True, type='int') aggregate_spec['vlan_id'] = dict(required=True, type='int')
# remove default in aggregate spec, to handle common arguments
remove_default_spec(aggregate_spec)
required_together = [['name', 'vlan_id']]
argument_spec = dict( argument_spec = dict(
aggregate=dict(type='list', elements='dict', options=aggregate_spec), aggregate=dict(type='list', elements='dict', options=aggregate_spec, required_together=required_together)
purge=dict(default=False, type='bool')
) )
argument_spec.update(element_spec) argument_spec.update(element_spec)
argument_spec.update(junos_argument_spec) argument_spec.update(junos_argument_spec)
required_one_of = [['aggregate', 'name']] required_one_of = [['aggregate', 'name']]
required_together = [['name', 'vlan_id']] mutually_exclusive = [['aggregate', 'name']]
mutually_exclusive = [['aggregate', 'name'],
['aggregate', 'vlan_id'],
['aggregate', 'description'],
['aggregate', 'interfaces'],
['aggregate', 'state'],
['aggregate', 'active']]
module = AnsibleModule(argument_spec=argument_spec, module = AnsibleModule(argument_spec=argument_spec,
required_one_of=required_one_of, required_one_of=required_one_of,
@ -197,7 +196,13 @@ def main():
requests = list() requests = list()
for param in params: for param in params:
# if key doesn't exist in the item, get it from module.params
for key in param:
if param.get(key) is None:
param[key] = module.params[key]
item = param.copy() item = param.copy()
validate_param_values(module, param_to_xpath_map, param=item) validate_param_values(module, param_to_xpath_map, param=item)
want = map_params_to_obj(module, param_to_xpath_map, param=item) want = map_params_to_obj(module, param_to_xpath_map, param=item)

View file

@ -55,11 +55,6 @@ options:
JUNOS device. Ths list entries can either be the VRF name or a hash JUNOS device. Ths list entries can either be the VRF name or a hash
of VRF definitions and attributes. This argument is mutually of VRF definitions and attributes. This argument is mutually
exclusive with the C(name) argument. exclusive with the C(name) argument.
purge:
description:
- Instructs the module to consider the VRF definition absolute.
It will remove any previously configured VRFs on the device.
default: false
state: state:
description: description:
- Configures the state of the VRF definition - Configures the state of the VRF definition
@ -78,7 +73,7 @@ requirements:
- ncclient (>=v0.5.2) - ncclient (>=v0.5.2)
notes: notes:
- This module requires the netconf system service be enabled on - This module requires the netconf system service be enabled on
the remote device being managed the remote device being managed.
""" """
EXAMPLES = """ EXAMPLES = """
- name: Configure vrf configuration - name: Configure vrf configuration
@ -135,7 +130,6 @@ EXAMPLES = """
- ge-0/0/2 - ge-0/0/2
rd: 1.1.1.1:10 rd: 1.1.1.1:10
target: target:65514:113 target: target:65514:113
state: present
- name: test-2 - name: test-2
description: test-vrf-2 description: test-vrf-2
interfaces: interfaces:
@ -143,7 +137,7 @@ EXAMPLES = """
- ge-0/0/5 - ge-0/0/5
rd: 2.2.2.2:10 rd: 2.2.2.2:10
target: target:65515:114 target: target:65515:114
state: present state: present
""" """
RETURN = """ RETURN = """
@ -164,7 +158,10 @@ diff.prepared:
""" """
import collections import collections
from copy import deepcopy
from ansible.module_utils.basic import AnsibleModule from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.network_common import remove_default_spec
from ansible.module_utils.junos import junos_argument_spec, check_args from ansible.module_utils.junos import junos_argument_spec, check_args
from ansible.module_utils.junos import load_config, map_params_to_obj, map_obj_to_ele, to_param_list from ansible.module_utils.junos import load_config, map_params_to_obj, map_obj_to_ele, to_param_list
from ansible.module_utils.junos import commit_configuration, discard_changes, locked_config from ansible.module_utils.junos import commit_configuration, discard_changes, locked_config
@ -190,25 +187,21 @@ def main():
active=dict(default=True, type='bool') active=dict(default=True, type='bool')
) )
aggregate_spec = element_spec.copy() aggregate_spec = deepcopy(element_spec)
aggregate_spec['name'] = dict(required=True) aggregate_spec['name'] = dict(required=True)
# remove default in aggregate spec, to handle common arguments
remove_default_spec(aggregate_spec)
argument_spec = dict( argument_spec = dict(
aggregate=dict(type='list', elements='dict', options=aggregate_spec), aggregate=dict(type='list', elements='dict', options=aggregate_spec),
purge=dict(default=False, type='bool')
) )
argument_spec.update(element_spec) argument_spec.update(element_spec)
argument_spec.update(junos_argument_spec) argument_spec.update(junos_argument_spec)
required_one_of = [['aggregate', 'name']] required_one_of = [['aggregate', 'name']]
mutually_exclusive = [['aggregate', 'name'], mutually_exclusive = [['aggregate', 'name']]
['aggregate', 'description'],
['aggregate', 'rd'],
['aggregate', 'interfaces'],
['aggregate', 'target'],
['aggregate', 'state'],
['aggregate', 'active']]
module = AnsibleModule(argument_spec=argument_spec, module = AnsibleModule(argument_spec=argument_spec,
supports_check_mode=True, supports_check_mode=True,
@ -239,8 +232,12 @@ def main():
requests = list() requests = list()
for param in params: for param in params:
item = param.copy() # if key doesn't exist in the item, get it from module.params
for key in param:
if param.get(key) is None:
param[key] = module.params[key]
item = param.copy()
item['type'] = 'vrf' item['type'] = 'vrf'
want = map_params_to_obj(module, param_to_xpath_map, param=item) want = map_params_to_obj(module, param_to_xpath_map, param=item)

View file

@ -68,6 +68,28 @@ EXAMPLES = """
name: 1.1.1.1 name: 1.1.1.1
facility: kernel facility: kernel
level: critical level: critical
- name: Configure file logging using aggregate
net_logging:
dest: file
aggregate:
- name: test-1
facility: pfe
level: critical
- name: test-2
facility: kernel
level: emergency
- name: Delete file logging using aggregate
net_logging:
dest: file
aggregate:
- name: test-1
facility: pfe
level: critical
- name: test-2
facility: kernel
level: emergency
state: absent
""" """
RETURN = """ RETURN = """

View file

@ -1,7 +1,7 @@
--- ---
- debug: msg="START junos_interface netconf/basic.yaml" - debug: msg="START junos_interface netconf/basic.yaml"
- name: setup - remove interface - name: setup remove interface
junos_interface: junos_interface:
name: ge-0/0/1 name: ge-0/0/1
description: test-interface description: test-interface
@ -169,8 +169,9 @@
- name: Set interface on aggregate - name: Set interface on aggregate
junos_interface: junos_interface:
aggregate: aggregate:
- { name: ge-0/0/1, description: test-interface-1, speed: 1g, duplex: full, mtu: 512} - { name: ge-0/0/1, description: test-interface-1, speed: 1g, mtu: 512}
- { name: ge-0/0/2, description: test-interface-2, speed: 10m, duplex: full, mtu: 256} - { name: ge-0/0/2, description: test-interface-2, speed: 10m, mtu: 256}
duplex: full
provider: "{{ netconf }}" provider: "{{ netconf }}"
register: result register: result
@ -190,8 +191,9 @@
- name: Set interface on aggregate (idempotent) - name: Set interface on aggregate (idempotent)
junos_interface: junos_interface:
aggregate: aggregate:
- { name: ge-0/0/1, description: test-interface-1, speed: 1g, duplex: full, mtu: 512} - { name: ge-0/0/1, description: test-interface-1, speed: 1g, mtu: 512 }
- { name: ge-0/0/2, description: test-interface-2, speed: 10m, duplex: full, mtu: 256} - { name: ge-0/0/2, description: test-interface-2, speed: 10m, mtu: 256 }
duplex: full
provider: "{{ netconf }}" provider: "{{ netconf }}"
register: result register: result
@ -202,8 +204,9 @@
- name: Disable interface on aggregate - name: Disable interface on aggregate
junos_interface: junos_interface:
aggregate: aggregate:
- { name: ge-0/0/1, description: test-interface-1, speed: 1g, duplex: full, mtu: 512, enabled: False} - name: ge-0/0/1
- { name: ge-0/0/2, description: test-interface-2, speed: 10m, duplex: full, mtu: 256, enabled: False} - name: ge-0/0/2
enabled: False
provider: "{{ netconf }}" provider: "{{ netconf }}"
register: result register: result
@ -215,8 +218,9 @@
- name: Enable interface on aggregate - name: Enable interface on aggregate
junos_interface: junos_interface:
aggregate: aggregate:
- { name: ge-0/0/1, description: test-interface-1, speed: 1g, duplex: full, mtu: 512, enabled: True} - name: ge-0/0/1
- { name: ge-0/0/2, description: test-interface-2, speed: 10m, duplex: full, mtu: 256, enabled: True} - name: ge-0/0/2
enabled: True
provider: "{{ netconf }}" provider: "{{ netconf }}"
register: result register: result
@ -228,8 +232,10 @@
- name: Deactivate interface configuration on aggregate - name: Deactivate interface configuration on aggregate
junos_interface: junos_interface:
aggregate: aggregate:
- { name: ge-0/0/1, description: test-interface-1, speed: 1g, duplex: full, mtu: 512, active: False} - { name: ge-0/0/1, description: test-interface-1, speed: 1g, mtu: 512 }
- { name: ge-0/0/2, description: test-interface-2, speed: 10m, duplex: full, mtu: 256, active: False} - { name: ge-0/0/2, description: test-interface-2, speed: 10m, mtu: 256 }
duplex: full
active: False
provider: "{{ netconf }}" provider: "{{ netconf }}"
register: result register: result
@ -242,8 +248,10 @@
- name: Activate interface configuration on aggregate - name: Activate interface configuration on aggregate
junos_interface: junos_interface:
aggregate: aggregate:
- { name: ge-0/0/1, description: test-interface-1, speed: 1g, duplex: full, mtu: 512, active: True} - { name: ge-0/0/1, description: test-interface-1, speed: 1g, mtu: 512 }
- { name: ge-0/0/2, description: test-interface-2, speed: 10m, duplex: full, mtu: 256, active: True} - { name: ge-0/0/2, description: test-interface-2, speed: 10m, mtu: 256 }
duplex: full
active: True
provider: "{{ netconf }}" provider: "{{ netconf }}"
register: result register: result
@ -256,8 +264,9 @@
- name: Delete interface on aggregate - name: Delete interface on aggregate
junos_interface: junos_interface:
aggregate: aggregate:
- { name: ge-0/0/1, description: test-interface-1, speed: 1g, duplex: full, mtu: 512, state: absent} - name: ge-0/0/1
- { name: ge-0/0/2, description: test-interface-2, speed: 10m, duplex: full, mtu: 256, state: absent} - name: ge-0/0/2
state: absent
provider: "{{ netconf }}" provider: "{{ netconf }}"
register: result register: result
@ -274,11 +283,12 @@
- result.diff.prepared | search("\- * mtu 256") - result.diff.prepared | search("\- * mtu 256")
- result.diff.prepared | search("\- *link-mode full-duplex") - result.diff.prepared | search("\- *link-mode full-duplex")
- name: Delete interface aggregate (idempotent) - name: Delete interface on aggregate (idempotent)
junos_interface: junos_interface:
aggregate: aggregate:
- { name: ge-0/0/1, description: test-interface-1, speed: 1g, duplex: full, mtu: 512, state: absent} - name: ge-0/0/1
- { name: ge-0/0/2, description: test-interface-2, speed: 10m, duplex: full, mtu: 256, state: absent} - name: ge-0/0/2
state: absent
provider: "{{ netconf }}" provider: "{{ netconf }}"
register: result register: result

View file

@ -159,11 +159,10 @@
- name: ge-0/0/1 - name: ge-0/0/1
ipv4: 1.1.1.1 ipv4: 1.1.1.1
ipv6: fd5d:12c9:2201:1::1 ipv6: fd5d:12c9:2201:1::1
active: True
- name: ge-0/0/2 - name: ge-0/0/2
ipv4: 2.2.2.2 ipv4: 2.2.2.2
ipv6: fd5d:12c9:2201:2::2 ipv6: fd5d:12c9:2201:2::2
active: True active: True
provider: "{{ netconf }}" provider: "{{ netconf }}"
register: result register: result
@ -177,11 +176,10 @@
- name: ge-0/0/1 - name: ge-0/0/1
ipv4: 1.1.1.1 ipv4: 1.1.1.1
ipv6: fd5d:12c9:2201:1::1 ipv6: fd5d:12c9:2201:1::1
active: False
- name: ge-0/0/2 - name: ge-0/0/2
ipv4: 2.2.2.2 ipv4: 2.2.2.2
ipv6: fd5d:12c9:2201:2::2 ipv6: fd5d:12c9:2201:2::2
active: False active: False
provider: "{{ netconf }}" provider: "{{ netconf }}"
register: result register: result
@ -199,11 +197,10 @@
- name: ge-0/0/1 - name: ge-0/0/1
ipv4: 1.1.1.1 ipv4: 1.1.1.1
ipv6: fd5d:12c9:2201:1::1 ipv6: fd5d:12c9:2201:1::1
active: True
- name: ge-0/0/2 - name: ge-0/0/2
ipv4: 2.2.2.2 ipv4: 2.2.2.2
ipv6: fd5d:12c9:2201:2::2 ipv6: fd5d:12c9:2201:2::2
active: True active: True
provider: "{{ netconf }}" provider: "{{ netconf }}"
register: result register: result
@ -221,11 +218,10 @@
- name: ge-0/0/1 - name: ge-0/0/1
ipv4: 1.1.1.1 ipv4: 1.1.1.1
ipv6: fd5d:12c9:2201:1::1 ipv6: fd5d:12c9:2201:1::1
state: absent
- name: ge-0/0/2 - name: ge-0/0/2
ipv4: 2.2.2.2 ipv4: 2.2.2.2
ipv6: fd5d:12c9:2201:2::2 ipv6: fd5d:12c9:2201:2::2
state: absent state: absent
provider: "{{ netconf }}" provider: "{{ netconf }}"
register: result register: result
@ -247,11 +243,10 @@
- name: ge-0/0/1 - name: ge-0/0/1
ipv4: 1.1.1.1 ipv4: 1.1.1.1
ipv6: fd5d:12c9:2201:1::1 ipv6: fd5d:12c9:2201:1::1
state: absent
- name: ge-0/0/2 - name: ge-0/0/2
ipv4: 2.2.2.2 ipv4: 2.2.2.2
ipv6: fd5d:12c9:2201:2::2 ipv6: fd5d:12c9:2201:2::2
state: absent state: absent
provider: "{{ netconf }}" provider: "{{ netconf }}"
register: result register: result

View file

@ -324,8 +324,15 @@
- name: Deactivate file logging configuration using aggregate - name: Deactivate file logging configuration using aggregate
junos_logging: junos_logging:
aggregate: aggregate:
- {dest: file, name: test-1, facility: pfe, level: critical, active: False} - dest: file
- {dest: file, name: test-2, facility: kernel, level: emergency, active: False} name: test-1
facility: pfe
level: critical
- dest: file
name: test-2
facility: kernel
level: emergency
active: False
provider: "{{ netconf }}" provider: "{{ netconf }}"
register: result register: result
@ -340,8 +347,9 @@
- name: activate file logging configuration using aggregate - name: activate file logging configuration using aggregate
junos_logging: junos_logging:
aggregate: aggregate:
- {dest: file, name: test-1, facility: pfe, level: critical, active: True} - { dest: file, name: test-1, facility: pfe, level: critical }
- {dest: file, name: test-2, facility: kernel, level: emergency, active: True} - { dest: file, name: test-2, facility: kernel, level: emergency }
active: True
provider: "{{ netconf }}" provider: "{{ netconf }}"
register: result register: result
@ -356,8 +364,9 @@
- name: Delete file logging using aggregate - name: Delete file logging using aggregate
junos_logging: junos_logging:
aggregate: aggregate:
- {dest: file, name: test-1, facility: pfe, level: critical, state: absent} - { dest: file, name: test-1, facility: pfe, level: critical }
- {dest: file, name: test-2, facility: kernel, level: emergency, state: absent} - { dest: file, name: test-2, facility: kernel, level: emergency }
state: absent
provider: "{{ netconf }}" provider: "{{ netconf }}"
register: result register: result
@ -372,8 +381,9 @@
- name: Delete file logging using aggregate (idempotent) - name: Delete file logging using aggregate (idempotent)
junos_logging: junos_logging:
aggregate: aggregate:
- {dest: file, name: test-1, facility: pfe, level: critical, state: absent} - { dest: file, name: test-1, facility: pfe, level: critical }
- {dest: file, name: test-2, facility: kernel, level: emergency, state: absent} - { dest: file, name: test-2, facility: kernel, level: emergency }
state: absent
provider: "{{ netconf }}" provider: "{{ netconf }}"
register: result register: result

View file

@ -144,15 +144,17 @@
- name: Setup static route for aggegrate - name: Setup static route for aggegrate
junos_static_route: junos_static_route:
aggregate: aggregate:
- {address: 4.4.4.0/24, state: absent} - address: 4.4.4.0/24
- {address: 5.5.5.0/24, state: absent} - address: 5.5.5.0/24
state: absent
provider: "{{ netconf }}" provider: "{{ netconf }}"
- name: Confgiure static route using aggegrate - name: Confgiure static route using aggegrate
junos_static_route: junos_static_route:
aggregate: aggregate:
- {address: 4.4.4.0/24, next_hop: 3.3.3.3, preference: 10, qualified_next_hop: 5.5.5.5, qualified_preference: 30} - {address: 4.4.4.0/24, next_hop: 3.3.3.3, preference: 10, qualified_next_hop: 5.5.5.5}
- {address: 5.5.5.0/24, next_hop: 6.6.6.6, preference: 11, qualified_next_hop: 7.7.7.7, qualified_preference: 12} - {address: 5.5.5.0/24, next_hop: 6.6.6.6, preference: 11, qualified_next_hop: 7.7.7.7}
qualified_preference: 30
provider: "{{ netconf }}" provider: "{{ netconf }}"
register: result register: result
@ -167,14 +169,16 @@
- result.diff.prepared | search("\+ *route 5.5.5.0/24") - result.diff.prepared | search("\+ *route 5.5.5.0/24")
- result.diff.prepared | search("\+ *next-hop 6.6.6.6") - result.diff.prepared | search("\+ *next-hop 6.6.6.6")
- result.diff.prepared | search("\+ *qualified-next-hop 7.7.7.7") - result.diff.prepared | search("\+ *qualified-next-hop 7.7.7.7")
- result.diff.prepared | search("\+ *preference 12") - result.diff.prepared | search("\+ *preference 30")
- result.diff.prepared | search("\+ *preference 11") - result.diff.prepared | search("\+ *preference 11")
- name: Deactivate static route configuration using aggegrate - name: Deactivate static route configuration using aggegrate
junos_static_route: junos_static_route:
aggregate: aggregate:
- {address: 4.4.4.0/24, next_hop: 3.3.3.3, preference: 10, qualified_next_hop: 5.5.5.5, qualified_preference: 30, active: False} - {address: 4.4.4.0/24, next_hop: 3.3.3.3, preference: 10, qualified_next_hop: 5.5.5.5}
- {address: 5.5.5.0/24, next_hop: 6.6.6.6, preference: 11, qualified_next_hop: 7.7.7.7, qualified_preference: 12, active: False} - {address: 5.5.5.0/24, next_hop: 6.6.6.6, preference: 11, qualified_next_hop: 7.7.7.7}
qualified_preference: 30
active: False
provider: "{{ netconf }}" provider: "{{ netconf }}"
register: result register: result
@ -191,8 +195,10 @@
- name: Activate static route configuration using aggegrate - name: Activate static route configuration using aggegrate
junos_static_route: junos_static_route:
aggregate: aggregate:
- {address: 4.4.4.0/24, next_hop: 3.3.3.3, preference: 10, qualified_next_hop: 5.5.5.5, qualified_preference: 30, active: True} - {address: 4.4.4.0/24, next_hop: 3.3.3.3, preference: 10, qualified_next_hop: 5.5.5.5}
- {address: 5.5.5.0/24, next_hop: 6.6.6.6, preference: 11, qualified_next_hop: 7.7.7.7, qualified_preference: 12, active: True} - {address: 5.5.5.0/24, next_hop: 6.6.6.6, preference: 11, qualified_next_hop: 7.7.7.7}
qualified_preference: 30
active: True
provider: "{{ netconf }}" provider: "{{ netconf }}"
register: result register: result
@ -209,8 +215,9 @@
- name: Delete static route configuration using aggegrate - name: Delete static route configuration using aggegrate
junos_static_route: junos_static_route:
aggregate: aggregate:
- {address: 4.4.4.0/24, state: absent} - address: 4.4.4.0/24
- {address: 5.5.5.0/24, state: absent} - address: 5.5.5.0/24
state: absent
provider: "{{ netconf }}" provider: "{{ netconf }}"
register: result register: result
@ -225,14 +232,15 @@
- result.diff.prepared | search("\- *route 5.5.5.0/24") - result.diff.prepared | search("\- *route 5.5.5.0/24")
- result.diff.prepared | search("\- *next-hop 6.6.6.6") - result.diff.prepared | search("\- *next-hop 6.6.6.6")
- result.diff.prepared | search("\- *qualified-next-hop 7.7.7.7") - result.diff.prepared | search("\- *qualified-next-hop 7.7.7.7")
- result.diff.prepared | search("\- *preference 12") - result.diff.prepared | search("\- *preference 30")
- result.diff.prepared | search("\- *preference 11") - result.diff.prepared | search("\- *preference 11")
- name: Delete static route configuration using aggegrate (idempotent) - name: Delete static route configuration using aggegrate (idempotent)
junos_static_route: junos_static_route:
aggregate: aggregate:
- {address: 4.4.4.0/24, state: absent} - address: 4.4.4.0/24
- {address: 5.5.5.0/24, state: absent} - address: 5.5.5.0/24
state: absent
provider: "{{ netconf }}" provider: "{{ netconf }}"
register: result register: result

View file

@ -106,15 +106,18 @@
- name: Setup vlan configuration for aggregate - name: Setup vlan configuration for aggregate
junos_vlan: junos_vlan:
aggregate: aggregate:
- { vlan_id: 159, name: test_vlan_1, state: absent } - vlan_id: 159
- { vlan_id: 160, name: test_vlan_2, state: absent } name: test_vlan_1
- vlan_id: 160
name: test_vlan_2
state: absent
provider: "{{ netconf }}" provider: "{{ netconf }}"
- name: Create vlan configuration using aggregate - name: Create vlan configuration using aggregate
junos_vlan: junos_vlan:
aggregate: aggregate:
- { vlan_id: 159, name: test_vlan_1, description: test vlan-1, state: present } - { vlan_id: 159, name: test_vlan_1, description: test vlan-1 }
- { vlan_id: 160, name: test_vlan_2, description: test vlan-2, state: present } - { vlan_id: 160, name: test_vlan_2, description: test vlan-2 }
provider: "{{ netconf }}" provider: "{{ netconf }}"
register: result register: result
@ -129,8 +132,9 @@
- name: Deactivate vlan configuration using aggregate - name: Deactivate vlan configuration using aggregate
junos_vlan: junos_vlan:
aggregate: aggregate:
- { vlan_id: 159, name: test_vlan_1, description: test vlan-1, active: False } - { vlan_id: 159, name: test_vlan_1, description: test vlan-1 }
- { vlan_id: 160, name: test_vlan_2, description: test vlan-2, active: False } - { vlan_id: 160, name: test_vlan_2, description: test vlan-2 }
active: False
provider: "{{ netconf }}" provider: "{{ netconf }}"
register: result register: result
@ -143,8 +147,9 @@
- name: activate vlan configuration using aggregate - name: activate vlan configuration using aggregate
junos_vlan: junos_vlan:
aggregate: aggregate:
- { vlan_id: 159, name: test_vlan_1, description: test vlan-1, active: True } - { vlan_id: 159, name: test_vlan_1, description: test vlan-1 }
- { vlan_id: 160, name: test_vlan_2, description: test vlan-2, active: True } - { vlan_id: 160, name: test_vlan_2, description: test vlan-2 }
active: True
provider: "{{ netconf }}" provider: "{{ netconf }}"
register: result register: result
@ -157,8 +162,11 @@
- name: Delete vlan configuration using aggregate - name: Delete vlan configuration using aggregate
junos_vlan: junos_vlan:
aggregate: aggregate:
- { vlan_id: 159, name: test_vlan_1, state: absent } - vlan_id: 159
- { vlan_id: 160, name: test_vlan_2, state: absent } name: test_vlan_1
- vlan_id: 160
name: test_vlan_2
state: absent
provider: "{{ netconf }}" provider: "{{ netconf }}"
register: result register: result

View file

@ -172,9 +172,8 @@
junos_vrf: junos_vrf:
aggregate: aggregate:
- name: test-1 - name: test-1
state: absent
- name: test-2 - name: test-2
state: absent state: absent
provider: "{{ netconf }}" provider: "{{ netconf }}"
register: result register: result
@ -188,7 +187,6 @@
- ge-0/0/2 - ge-0/0/2
rd: 1.1.1.1:10 rd: 1.1.1.1:10
target: target:65514:113 target: target:65514:113
state: present
- name: test-2 - name: test-2
description: test-vrf-2 description: test-vrf-2
interfaces: interfaces:
@ -196,7 +194,6 @@
- ge-0/0/5 - ge-0/0/5
rd: 2.2.2.2:10 rd: 2.2.2.2:10
target: target:65515:114 target: target:65515:114
state: present
provider: "{{ netconf }}" provider: "{{ netconf }}"
register: result register: result
@ -228,8 +225,6 @@
- ge-0/0/2 - ge-0/0/2
rd: 1.1.1.1:10 rd: 1.1.1.1:10
target: target:65514:113 target: target:65514:113
state: present
active: False
- name: test-2 - name: test-2
description: test-vrf-2 description: test-vrf-2
interfaces: interfaces:
@ -237,8 +232,7 @@
- ge-0/0/5 - ge-0/0/5
rd: 2.2.2.2:10 rd: 2.2.2.2:10
target: target:65515:114 target: target:65515:114
state: present active: False
active: False
provider: "{{ netconf }}" provider: "{{ netconf }}"
register: result register: result
@ -266,8 +260,6 @@
- ge-0/0/2 - ge-0/0/2
rd: 1.1.1.1:10 rd: 1.1.1.1:10
target: target:65514:113 target: target:65514:113
state: present
active: True
- name: test-2 - name: test-2
description: test-vrf-2 description: test-vrf-2
interfaces: interfaces:
@ -275,8 +267,7 @@
- ge-0/0/5 - ge-0/0/5
rd: 2.2.2.2:10 rd: 2.2.2.2:10
target: target:65515:114 target: target:65515:114
state: present active: True
active: True
provider: "{{ netconf }}" provider: "{{ netconf }}"
register: result register: result
@ -298,9 +289,8 @@
junos_vrf: junos_vrf:
aggregate: aggregate:
- name: test-1 - name: test-1
state: absent
- name: test-2 - name: test-2
state: absent state: absent
provider: "{{ netconf }}" provider: "{{ netconf }}"
register: result register: result
@ -326,9 +316,8 @@
junos_vrf: junos_vrf:
aggregate: aggregate:
- name: test-1 - name: test-1
state: absent
- name: test-2 - name: test-2
state: absent state: absent
provider: "{{ netconf }}" provider: "{{ netconf }}"
register: result register: result

View file

@ -1,7 +1,7 @@
--- ---
- debug: msg="START net_interface junos/basic.yaml" - debug: msg="START net_interface netconf/basic.yaml"
- name: setup - remove interface - name: setup remove interface
net_interface: net_interface:
name: ge-0/0/1 name: ge-0/0/1
description: test-interface description: test-interface
@ -74,17 +74,10 @@
provider: "{{ netconf }}" provider: "{{ netconf }}"
register: result register: result
- name: Get running configuration
junos_rpc:
rpc: get-configuration
provider: "{{ netconf }}"
register: config
- assert: - assert:
that: that:
- "result.changed == true" - "result.changed == true"
- result.diff.prepared | search("\+ *disable") - result.diff.prepared | search("\+ *disable")
- "'<name>ge-0/0/1</name>' in config.xml"
- name: Enable interface - name: Enable interface
net_interface: net_interface:
@ -94,17 +87,10 @@
provider: "{{ netconf }}" provider: "{{ netconf }}"
register: result register: result
- name: Get running configuration
junos_rpc:
rpc: get-configuration
provider: "{{ netconf }}"
register: config
- assert: - assert:
that: that:
- "result.changed == true" - "result.changed == true"
- result.diff.prepared | search("\- *disable") - result.diff.prepared | search("\- *disable")
- "'<name>ge-0/0/1</name>' in config.xml"
- name: Delete interface - name: Delete interface
net_interface: net_interface:
@ -142,8 +128,9 @@
- name: Set interface on aggregate - name: Set interface on aggregate
net_interface: net_interface:
aggregate: aggregate:
- { name: ge-0/0/1, description: test-interface-1, speed: 1g, duplex: full, mtu: 512} - { name: ge-0/0/1, description: test-interface-1, speed: 1g, mtu: 512}
- { name: ge-0/0/2, description: test-interface-2, speed: 10m, duplex: full, mtu: 256} - { name: ge-0/0/2, description: test-interface-2, speed: 10m, mtu: 256}
duplex: full
provider: "{{ netconf }}" provider: "{{ netconf }}"
register: result register: result
@ -163,8 +150,9 @@
- name: Set interface on aggregate (idempotent) - name: Set interface on aggregate (idempotent)
net_interface: net_interface:
aggregate: aggregate:
- { name: ge-0/0/1, description: test-interface-1, speed: 1g, duplex: full, mtu: 512} - { name: ge-0/0/1, description: test-interface-1, speed: 1g, mtu: 512 }
- { name: ge-0/0/2, description: test-interface-2, speed: 10m, duplex: full, mtu: 256} - { name: ge-0/0/2, description: test-interface-2, speed: 10m, mtu: 256 }
duplex: full
provider: "{{ netconf }}" provider: "{{ netconf }}"
register: result register: result
@ -175,8 +163,9 @@
- name: Disable interface on aggregate - name: Disable interface on aggregate
net_interface: net_interface:
aggregate: aggregate:
- { name: ge-0/0/1, description: test-interface-1, speed: 1g, duplex: full, mtu: 512, enabled: False} - name: ge-0/0/1
- { name: ge-0/0/2, description: test-interface-2, speed: 10m, duplex: full, mtu: 256, enabled: False} - name: ge-0/0/2
enabled: False
provider: "{{ netconf }}" provider: "{{ netconf }}"
register: result register: result
@ -188,8 +177,9 @@
- name: Enable interface on aggregate - name: Enable interface on aggregate
net_interface: net_interface:
aggregate: aggregate:
- { name: ge-0/0/1, description: test-interface-1, speed: 1g, duplex: full, mtu: 512, enabled: True} - name: ge-0/0/1
- { name: ge-0/0/2, description: test-interface-2, speed: 10m, duplex: full, mtu: 256, enabled: True} - name: ge-0/0/2
enabled: True
provider: "{{ netconf }}" provider: "{{ netconf }}"
register: result register: result
@ -201,8 +191,9 @@
- name: Delete interface on aggregate - name: Delete interface on aggregate
net_interface: net_interface:
aggregate: aggregate:
- { name: ge-0/0/1, description: test-interface-1, speed: 1g, duplex: full, mtu: 512, state: absent} - { name: ge-0/0/1, description: test-interface-1 }
- { name: ge-0/0/2, description: test-interface-2, speed: 10m, duplex: full, mtu: 256, state: absent} - { name: ge-0/0/2, description: test-interface-2 }
state: absent
provider: "{{ netconf }}" provider: "{{ netconf }}"
register: result register: result
@ -219,11 +210,12 @@
- result.diff.prepared | search("\- * mtu 256") - result.diff.prepared | search("\- * mtu 256")
- result.diff.prepared | search("\- *link-mode full-duplex") - result.diff.prepared | search("\- *link-mode full-duplex")
- name: Delete interface aggregate (idempotent) - name: Delete interface on aggregate (idempotent)
net_interface: net_interface:
aggregate: aggregate:
- { name: ge-0/0/1, description: test-interface-1, speed: 1g, duplex: full, mtu: 512, state: absent} - name: ge-0/0/1
- { name: ge-0/0/2, description: test-interface-2, speed: 10m, duplex: full, mtu: 256, state: absent} - name: ge-0/0/2
state: absent
provider: "{{ netconf }}" provider: "{{ netconf }}"
register: result register: result

View file

@ -29,8 +29,8 @@
- "result.changed == true" - "result.changed == true"
- "'<name>1.1.1.1/32</name>' in config.xml" - "'<name>1.1.1.1/32</name>' in config.xml"
- "'<name>fd5d:12c9:2201:1::1/128</name>' in config.xml" - "'<name>fd5d:12c9:2201:1::1/128</name>' in config.xml"
- "'+ address 1.1.1.1/32;' in result.diff.prepared" - result.diff.prepared | search("\+ *address 1.1.1.1/32")
- "'+ address fd5d:12c9:2201:1::1/128;' in result.diff.prepared" - result.diff.prepared | search("\+ *address fd5d:12c9:2201:1::1/128")
- name: Configure interface address (idempotent) - name: Configure interface address (idempotent)
net_l3_interface: net_l3_interface:
@ -65,8 +65,8 @@
- "result.changed == true" - "result.changed == true"
- "'<name>1.1.1.1/32</name>' not in config.xml" - "'<name>1.1.1.1/32</name>' not in config.xml"
- "'<name>fd5d:12c9:2201:1::1/128</name>' not in config.xml" - "'<name>fd5d:12c9:2201:1::1/128</name>' not in config.xml"
- "'- address 1.1.1.1/32;' in result.diff.prepared" - result.diff.prepared | search("\- *address 1.1.1.1/32")
- "'- address fd5d:12c9:2201:1::1/128;' in result.diff.prepared" - result.diff.prepared | search("\- *address fd5d:12c9:2201:1::1/128")
- name: Delete interface address (idempotent) - name: Delete interface address (idempotent)
net_l3_interface: net_l3_interface:
@ -129,11 +129,10 @@
- name: ge-0/0/1 - name: ge-0/0/1
ipv4: 1.1.1.1 ipv4: 1.1.1.1
ipv6: fd5d:12c9:2201:1::1 ipv6: fd5d:12c9:2201:1::1
active: True
- name: ge-0/0/2 - name: ge-0/0/2
ipv4: 2.2.2.2 ipv4: 2.2.2.2
ipv6: fd5d:12c9:2201:2::2 ipv6: fd5d:12c9:2201:2::2
active: True active: True
provider: "{{ netconf }}" provider: "{{ netconf }}"
register: result register: result
@ -147,11 +146,10 @@
- name: ge-0/0/1 - name: ge-0/0/1
ipv4: 1.1.1.1 ipv4: 1.1.1.1
ipv6: fd5d:12c9:2201:1::1 ipv6: fd5d:12c9:2201:1::1
state: absent
- name: ge-0/0/2 - name: ge-0/0/2
ipv4: 2.2.2.2 ipv4: 2.2.2.2
ipv6: fd5d:12c9:2201:2::2 ipv6: fd5d:12c9:2201:2::2
state: absent state: absent
provider: "{{ netconf }}" provider: "{{ netconf }}"
register: result register: result
@ -173,11 +171,10 @@
- name: ge-0/0/1 - name: ge-0/0/1
ipv4: 1.1.1.1 ipv4: 1.1.1.1
ipv6: fd5d:12c9:2201:1::1 ipv6: fd5d:12c9:2201:1::1
state: absent
- name: ge-0/0/2 - name: ge-0/0/2
ipv4: 2.2.2.2 ipv4: 2.2.2.2
ipv6: fd5d:12c9:2201:2::2 ipv6: fd5d:12c9:2201:2::2
state: absent state: absent
provider: "{{ netconf }}" provider: "{{ netconf }}"
register: result register: result

View file

@ -126,8 +126,14 @@
- name: Configure file logging using aggregate - name: Configure file logging using aggregate
net_logging: net_logging:
aggregate: aggregate:
- {dest: file, name: test-1, facility: pfe, level: critical, active: True} - dest: file
- {dest: file, name: test-2, facility: kernel, level: emergency, active: True} name: test-1
facility: pfe
level: critical
- dest: file
name: test-2
facility: kernel
level: emergency
provider: "{{ netconf }}" provider: "{{ netconf }}"
register: result register: result
@ -142,8 +148,15 @@
- name: Delete file logging using aggregate - name: Delete file logging using aggregate
net_logging: net_logging:
aggregate: aggregate:
- {dest: file, name: test-1, facility: pfe, level: critical, state: absent} - dest: file
- {dest: file, name: test-2, facility: kernel, level: emergency, state: absent} name: test-1
facility: pfe
level: critical
- dest: file
name: test-2
facility: kernel
level: emergency
state: absent
provider: "{{ netconf }}" provider: "{{ netconf }}"
register: result register: result
@ -154,3 +167,22 @@
- result.diff.prepared | search("\- *pfe critical") - result.diff.prepared | search("\- *pfe critical")
- result.diff.prepared | search("\- *file test-2") - result.diff.prepared | search("\- *file test-2")
- result.diff.prepared | search("\- *kernel emergency") - result.diff.prepared | search("\- *kernel emergency")
- name: Delete file logging using aggregate (idempotent)
net_logging:
aggregate:
- dest: file
name: test-1
facility: pfe
level: critical
- dest: file
name: test-2
facility: kernel
level: emergency
state: absent
provider: "{{ netconf }}"
register: result
- assert:
that:
- 'result.changed == false'

View file

@ -62,15 +62,18 @@
- name: Setup vlan configuration for aggregate - name: Setup vlan configuration for aggregate
net_vlan: net_vlan:
aggregate: aggregate:
- { vlan_id: 159, name: test_vlan_1, state: absent } - vlan_id: 159
- { vlan_id: 160, name: test_vlan_2, state: absent } name: test_vlan_1
- vlan_id: 160
name: test_vlan_2
state: absent
provider: "{{ netconf }}" provider: "{{ netconf }}"
- name: Create vlan configuration using aggregate - name: Create vlan configuration using aggregate
net_vlan: net_vlan:
aggregate: aggregate:
- { vlan_id: 159, name: test_vlan_1, description: test vlan-1, state: present } - { vlan_id: 159, name: test_vlan_1, description: test vlan-1 }
- { vlan_id: 160, name: test_vlan_2, description: test vlan-2, state: present } - { vlan_id: 160, name: test_vlan_2, description: test vlan-2 }
provider: "{{ netconf }}" provider: "{{ netconf }}"
register: result register: result
@ -83,10 +86,13 @@
- result.diff.prepared | search("\+ *vlan-id 160") - result.diff.prepared | search("\+ *vlan-id 160")
- name: Delete vlan configuration using aggregate - name: Delete vlan configuration using aggregate
junos_vlan: net_vlan:
aggregate: aggregate:
- { vlan_id: 159, name: test_vlan_1, state: absent } - vlan_id: 159
- { vlan_id: 160, name: test_vlan_2, state: absent } name: test_vlan_1
- vlan_id: 160
name: test_vlan_2
state: absent
provider: "{{ netconf }}" provider: "{{ netconf }}"
register: result register: result
@ -99,10 +105,13 @@
- result.diff.prepared | search("\- *vlan-id 160") - result.diff.prepared | search("\- *vlan-id 160")
- name: Delete vlan configuration using aggregate (idempotent) - name: Delete vlan configuration using aggregate (idempotent)
junos_vlan: net_vlan:
aggregate: aggregate:
- { vlan_id: 159, name: test_vlan_1, state: absent } - vlan_id: 159
- { vlan_id: 160, name: test_vlan_2, state: absent } name: test_vlan_1
- vlan_id: 160
name: test_vlan_2
state: absent
provider: "{{ netconf }}" provider: "{{ netconf }}"
register: result register: result

View file

@ -121,9 +121,8 @@
net_vrf: net_vrf:
aggregate: aggregate:
- name: test-1 - name: test-1
state: absent
- name: test-2 - name: test-2
state: absent state: absent
provider: "{{ netconf }}" provider: "{{ netconf }}"
register: result register: result
@ -137,7 +136,6 @@
- ge-0/0/2 - ge-0/0/2
rd: 1.1.1.1:10 rd: 1.1.1.1:10
target: target:65514:113 target: target:65514:113
state: present
- name: test-2 - name: test-2
description: test-vrf-2 description: test-vrf-2
interfaces: interfaces:
@ -145,7 +143,6 @@
- ge-0/0/5 - ge-0/0/5
rd: 2.2.2.2:10 rd: 2.2.2.2:10
target: target:65515:114 target: target:65515:114
state: present
provider: "{{ netconf }}" provider: "{{ netconf }}"
register: result register: result
@ -171,9 +168,8 @@
net_vrf: net_vrf:
aggregate: aggregate:
- name: test-1 - name: test-1
state: absent
- name: test-2 - name: test-2
state: absent state: absent
provider: "{{ netconf }}" provider: "{{ netconf }}"
register: result register: result
@ -199,9 +195,8 @@
net_vrf: net_vrf:
aggregate: aggregate:
- name: test-1 - name: test-1
state: absent
- name: test-2 - name: test-2
state: absent state: absent
provider: "{{ netconf }}" provider: "{{ netconf }}"
register: result register: result