diff --git a/lib/ansible/module_utils/network_common.py b/lib/ansible/module_utils/network_common.py index ff839c7bae6..898618948a9 100644 --- a/lib/ansible/module_utils/network_common.py +++ b/lib/ansible/module_utils/network_common.py @@ -329,6 +329,12 @@ def ternary(value, true_val, 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: def __init__(self): diff --git a/lib/ansible/modules/network/junos/junos_banner.py b/lib/ansible/modules/network/junos/junos_banner.py index 3e4500984e2..11974c8c04e 100644 --- a/lib/ansible/modules/network/junos/junos_banner.py +++ b/lib/ansible/modules/network/junos/junos_banner.py @@ -52,7 +52,7 @@ requirements: - ncclient (>=v0.5.2) notes: - This module requires the netconf system service be enabled on - the remote device being managed + the remote device being managed. """ EXAMPLES = """ diff --git a/lib/ansible/modules/network/junos/junos_interface.py b/lib/ansible/modules/network/junos/junos_interface.py index a0c5973e4b3..43e3e105e5d 100644 --- a/lib/ansible/modules/network/junos/junos_interface.py +++ b/lib/ansible/modules/network/junos/junos_interface.py @@ -72,7 +72,7 @@ requirements: - ncclient (>=v0.5.2) notes: - This module requires the netconf system service be enabled on - the remote device being managed + the remote device being managed. """ EXAMPLES = """ @@ -119,14 +119,20 @@ EXAMPLES = """ - name: Create interface using aggregate junos_interface: aggregate: - - { name: ge-0/0/1, description: test-interface-1, speed: 1g, duplex: half, mtu: 512} - - { name: ge-0/0/2, description: test-interface-2, speed: 10m, duplex: full, mtu: 256} + - name: ge-0/0/1 + description: test-interface-1 + - name: ge-0/0/2 + description: test-interface-2 + speed: 1g + duplex: full + mtu: 512 - name: Delete interface using aggregate junos_interface: aggregate: - - { name: ge-0/0/1, description: test-interface-1, state: absent} - - { name: ge-0/0/2, description: test-interface-2, state: absent} + - name: ge-0/0/1 + - name: ge-0/0/2 + state: absent - name: Check intent arguments junos_interface: @@ -155,10 +161,12 @@ diff.prepared: """ import collections +from copy import deepcopy from time import sleep from ansible.module_utils.basic import AnsibleModule 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.junos import junos_argument_spec, check_args 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(), rx_rate=dict(), delay=dict(default=10, type='int'), - state=dict(default='present', - choices=['present', 'absent', 'up', 'down']), + state=dict(default='present', choices=['present', 'absent', 'up', 'down']), active=dict(default=True, type='bool') ) - aggregate_spec = element_spec.copy() + 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( aggregate=dict(type='list', elements='dict', options=aggregate_spec), ) @@ -216,9 +226,7 @@ def main(): argument_spec.update(junos_argument_spec) required_one_of = [['name', 'aggregate']] - mutually_exclusive = [['name', 'aggregate'], - ['state', 'aggregate'], - ['active', 'aggregate']] + mutually_exclusive = [['name', 'aggregate']] module = AnsibleModule(argument_spec=argument_spec, required_one_of=required_one_of, @@ -253,6 +261,11 @@ def main(): requests = list() 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() state = item.get('state') item['disable'] = True if not item.get('enabled') else False diff --git a/lib/ansible/modules/network/junos/junos_l3_interface.py b/lib/ansible/modules/network/junos/junos_l3_interface.py index 68b490de764..6af093ec35d 100644 --- a/lib/ansible/modules/network/junos/junos_l3_interface.py +++ b/lib/ansible/modules/network/junos/junos_l3_interface.py @@ -38,10 +38,6 @@ options: default: 0 aggregate: description: List of L3 interfaces definitions - purge: - description: - - Purge L3 interfaces not defined in the aggregate parameter. - default: no state: description: - State of the L3 interface configuration. @@ -56,7 +52,7 @@ requirements: - ncclient (>=v0.5.2) notes: - This module requires the netconf system service be enabled on - the remote device being managed + the remote device being managed. """ EXAMPLES = """ @@ -84,10 +80,9 @@ EXAMPLES = """ aggregate: - name: ge-0/0/1 ipv4: 1.1.1.1 - state: absent - name: ge-0/0/2 ipv4: 2.2.2.2 - state: absent + state: absent """ RETURN = """ @@ -103,7 +98,10 @@ diff: """ import collections +from copy import deepcopy + 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 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 @@ -128,22 +126,21 @@ def main(): active=dict(default=True, type='bool') ) - aggregate_spec = element_spec.copy() + 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( aggregate=dict(type='list', elements='dict', options=aggregate_spec), - purge=dict(default=False, type='bool') ) argument_spec.update(element_spec) argument_spec.update(junos_argument_spec) required_one_of = [['name', 'aggregate']] - - mutually_exclusive = [['name', 'aggregate'], - ['state', 'aggregate'], - ['active', 'aggregate']] + mutually_exclusive = [['name', 'aggregate']] module = AnsibleModule(argument_spec=argument_spec, supports_check_mode=True, @@ -172,6 +169,11 @@ def main(): requests = list() 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() if not item['ipv4'] and not item['ipv6']: module.fail_json(msg="one of the following is required: ipv4,ipv6") diff --git a/lib/ansible/modules/network/junos/junos_linkagg.py b/lib/ansible/modules/network/junos/junos_linkagg.py index bcf546667c9..97939cdeb99 100644 --- a/lib/ansible/modules/network/junos/junos_linkagg.py +++ b/lib/ansible/modules/network/junos/junos_linkagg.py @@ -53,10 +53,6 @@ options: - Description of Interface. aggregate: description: List of link aggregation definitions. - purge: - description: - - Purge link aggregation groups not defined in the aggregates parameter. - default: no state: description: - State of the link aggregation group. @@ -71,7 +67,7 @@ requirements: - ncclient (>=v0.5.2) notes: - This module requires the netconf system service be enabled on - the remote device being managed + the remote device being managed. """ EXAMPLES = """ @@ -160,7 +156,10 @@ diff: """ import collections +from copy import deepcopy + 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 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 @@ -260,7 +259,7 @@ def main(): """ element_spec = 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'), min_links=dict(type='int'), device_count=dict(type='int'), @@ -269,27 +268,21 @@ def main(): active=dict(default=True, type='bool') ) - aggregate_spec = element_spec.copy() + 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( aggregate=dict(type='list', elements='dict', options=aggregate_spec), - purge=dict(default=False, type='bool') ) argument_spec.update(element_spec) argument_spec.update(junos_argument_spec) required_one_of = [['name', 'aggregate']] - - mutually_exclusive = [['name', 'aggregate'], - ['mode', 'aggregate'], - ['members', 'aggregate'], - ['min_links', 'aggregate'], - ['device_count', 'aggregate'], - ['description', 'aggregate'], - ['state', 'aggregate'], - ['active', 'aggregate']] + mutually_exclusive = [['name', 'aggregate']] module = AnsibleModule(argument_spec=argument_spec, supports_check_mode=True, @@ -307,8 +300,12 @@ def main(): params = to_param_list(module) requests = list() 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') item['disable'] = True if state == 'down' else False diff --git a/lib/ansible/modules/network/junos/junos_lldp.py b/lib/ansible/modules/network/junos/junos_lldp.py index 61edead2a48..b494ef40970 100644 --- a/lib/ansible/modules/network/junos/junos_lldp.py +++ b/lib/ansible/modules/network/junos/junos_lldp.py @@ -60,7 +60,7 @@ requirements: - ncclient (>=v0.5.2) notes: - This module requires the netconf system service be enabled on - the remote device being managed + the remote device being managed. """ EXAMPLES = """ diff --git a/lib/ansible/modules/network/junos/junos_lldp_interface.py b/lib/ansible/modules/network/junos/junos_lldp_interface.py index e876d77a2bc..26316928e39 100644 --- a/lib/ansible/modules/network/junos/junos_lldp_interface.py +++ b/lib/ansible/modules/network/junos/junos_lldp_interface.py @@ -49,7 +49,7 @@ requirements: - ncclient (>=v0.5.2) notes: - This module requires the netconf system service be enabled on - the remote device being managed + the remote device being managed. """ EXAMPLES = """ diff --git a/lib/ansible/modules/network/junos/junos_logging.py b/lib/ansible/modules/network/junos/junos_logging.py index 7077704b867..cc49f3b9096 100644 --- a/lib/ansible/modules/network/junos/junos_logging.py +++ b/lib/ansible/modules/network/junos/junos_logging.py @@ -40,10 +40,6 @@ options: - Set logging severity levels. aggregate: description: List of logging definitions. - purge: - description: - - Purge logging not defined in the aggregate parameter. - default: no state: description: - State of the logging configuration. @@ -71,6 +67,11 @@ options: - 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. required: false +requirements: + - ncclient (>=v0.5.2) +notes: + - This module requires the netconf system service be enabled on + the remote device being managed. """ EXAMPLES = """ @@ -100,15 +101,22 @@ EXAMPLES = """ - name: Configure file logging using aggregate junos_logging: + dest: file aggregate: - - {dest: file, name: test-1, facility: pfe, level: critical, active: True} - - {dest: file, name: test-2, facility: kernel, level: emergency, active: True} + - name: test-1 + facility: pfe + level: critical + - name: test-2 + facility: kernel + level: emergency + active: True - name: Delete file logging using aggregate junos_logging: aggregate: - - {dest: file, name: test-1, facility: pfe, level: critical, active: True, state: absent} - - {dest: file, name: test-2, facility: kernel, level: emergency, active: True, state: absent} + - { dest: file, name: test-1, facility: pfe, level: critical } + - { dest: file, name: test-2, facility: kernel, level: emergency } + state: absent """ RETURN = """ @@ -126,7 +134,10 @@ diff.prepared: """ import collections +from copy import deepcopy + 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 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 @@ -180,24 +191,18 @@ def main(): 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( - aggregate=dict(type='list', elements='dict', options=element_spec), - purge=dict(default=False, type='bool') + aggregate=dict(type='list', elements='dict', options=aggregate_spec), ) argument_spec.update(element_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']), ('dest', 'file', ['name', 'facility', 'level']), ('dest', 'user', ['name', 'facility', 'level']), @@ -205,7 +210,6 @@ def main(): module = AnsibleModule(argument_spec=argument_spec, required_if=required_if, - mutually_exclusive=mutually_exclusive, supports_check_mode=True) warnings = list() @@ -220,6 +224,13 @@ def main(): requests = list() 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() dest = item.get('dest') if dest == 'console' and item.get('name'): diff --git a/lib/ansible/modules/network/junos/junos_static_route.py b/lib/ansible/modules/network/junos/junos_static_route.py index bfff06dc773..b835b05506d 100644 --- a/lib/ansible/modules/network/junos/junos_static_route.py +++ b/lib/ansible/modules/network/junos/junos_static_route.py @@ -45,10 +45,6 @@ options: - Assign preference for qualified next hop. aggregate: description: List of static route definitions - purge: - description: - - Purge static routes not defined in the aggregate parameter. - default: no state: description: - State of the static route configuration. @@ -63,7 +59,7 @@ requirements: - ncclient (>=v0.5.2) notes: - This module requires the netconf system service be enabled on - the remote device being managed + the remote device being managed. """ EXAMPLES = """ @@ -104,14 +100,16 @@ EXAMPLES = """ - name: Configure static route using aggregate junos_static_route: 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: 5.5.5.0/24, next_hop: 6.6.6.6, preference: 11, qualified_next_hop: 7.7.7.7, qualified_preference: 12} + - { 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, qualified_next_hop: 7.7.7.7, qualified_preference: 12 } + preference: 10 - name: Delete static route using aggregate junos_static_route: aggregate: - - {address: 4.4.4.0/24, state: absent} - - {address: 5.5.5.0/24, state: absent} + - address: 4.4.4.0/24 + - address: 5.5.5.0/24 + state: absent """ RETURN = """ @@ -132,7 +130,10 @@ diff.prepared: """ import collections +from copy import deepcopy + 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 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 @@ -149,8 +150,8 @@ def main(): """ main entry point for module execution """ element_spec = dict( - address=dict(type='str', aliases=['prefix']), - next_hop=dict(type='str'), + address=dict(aliases=['prefix']), + next_hop=dict(), preference=dict(type='int', aliases=['admin_distance']), qualified_next_hop=dict(type='str'), qualified_preference=dict(type='int'), @@ -158,9 +159,12 @@ def main(): active=dict(default=True, type='bool') ) - aggregate_spec = element_spec.copy() + aggregate_spec = deepcopy(element_spec) aggregate_spec['address'] = dict(required=True) + # remove default in aggregate spec, to handle common arguments + remove_default_spec(aggregate_spec) + argument_spec = dict( aggregate=dict(type='list', elements='dict', options=aggregate_spec), purge=dict(default=False, type='bool') @@ -170,13 +174,7 @@ def main(): argument_spec.update(junos_argument_spec) required_one_of = [['aggregate', 'address']] - mutually_exclusive = [['aggregate', 'address'], - ['aggregate', 'next_hop'], - ['aggregate', 'preference'], - ['aggregate', 'qualified_next_hop'], - ['aggregate', 'qualified_preference'], - ['aggregate', 'state'], - ['aggregate', 'active']] + mutually_exclusive = [['aggregate', 'address']] module = AnsibleModule(argument_spec=argument_spec, required_one_of=required_one_of, @@ -206,6 +204,11 @@ def main(): requests = list() 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() if item['state'] == 'present': if not item['address'] and item['next_hop']: diff --git a/lib/ansible/modules/network/junos/junos_system.py b/lib/ansible/modules/network/junos/junos_system.py index 9a0fa789fa0..bb9cba2d8ad 100644 --- a/lib/ansible/modules/network/junos/junos_system.py +++ b/lib/ansible/modules/network/junos/junos_system.py @@ -64,7 +64,7 @@ requirements: - ncclient (>=v0.5.2) notes: - This module requires the netconf system service be enabled on - the remote device being managed + the remote device being managed. """ EXAMPLES = """ diff --git a/lib/ansible/modules/network/junos/junos_user.py b/lib/ansible/modules/network/junos/junos_user.py index a4a825c3562..5e7e6b73047 100644 --- a/lib/ansible/modules/network/junos/junos_user.py +++ b/lib/ansible/modules/network/junos/junos_user.py @@ -94,7 +94,7 @@ requirements: - ncclient (>=v0.5.2) notes: - This module requires the netconf system service be enabled on - the remote device being managed + the remote device being managed. """ EXAMPLES = """ @@ -142,7 +142,10 @@ diff.prepared: """ from functools import partial +from copy import deepcopy + 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 commit_configuration, discard_changes 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 module.params['name'] and module.params['purge']: return list() - elif not module.params['name']: - module.fail_json(msg='missing required argument: name') else: collection = [{'name': module.params['name']}] else: @@ -224,8 +225,6 @@ def map_params_to_obj(module): for item in aggregate: if not isinstance(item, dict): collection.append({'username': item}) - elif 'name' not in item: - module.fail_json(msg='missing required argument: name') else: collection.append(item) @@ -261,11 +260,17 @@ def main(): role=dict(choices=ROLES, default='unauthorized'), sshkey=dict(), 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( - 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') ) @@ -273,11 +278,7 @@ def main(): argument_spec.update(junos_argument_spec) required_one_of = [['aggregate', 'name']] - mutually_exclusive = [['aggregate', 'name'], - ['aggregate', 'full_name'], - ['aggregate', 'sshkey'], - ['aggregate', 'state'], - ['aggregate', 'active']] + mutually_exclusive = [['aggregate', 'name']] argument_spec.update(junos_argument_spec) diff --git a/lib/ansible/modules/network/junos/junos_vlan.py b/lib/ansible/modules/network/junos/junos_vlan.py index 7b19366030c..681d6cec3d6 100644 --- a/lib/ansible/modules/network/junos/junos_vlan.py +++ b/lib/ansible/modules/network/junos/junos_vlan.py @@ -39,10 +39,6 @@ options: configured correctly. aggregate: description: List of VLANs definitions. - purge: - description: - - Purge VLANs not defined in the aggregate parameter. - default: no state: description: - State of the VLAN configuration. @@ -57,7 +53,7 @@ requirements: - ncclient (>=v0.5.2) notes: - This module requires the netconf system service be enabled on - the remote device being managed + the remote device being managed. """ EXAMPLES = """ @@ -87,14 +83,15 @@ EXAMPLES = """ - name: Create vlan configuration using aggregate junos_vlan: aggregate: - - { vlan_id: 159, name: test_vlan_1, description: test vlan-1, state: present } - - { vlan_id: 160, name: test_vlan_2, description: test vlan-2, state: present } + - { vlan_id: 159, name: test_vlan_1, description: test vlan-1 } + - { vlan_id: 160, name: test_vlan_2, description: test vlan-2 } - name: Delete vlan configuration using aggregate junos_vlan: aggregate: - - { vlan_id: 159, name: test_vlan_1, state: absent } - - { vlan_id: 160, name: test_vlan_2, state: absent } + - { vlan_id: 159, name: test_vlan_1 } + - { vlan_id: 160, name: test_vlan_2 } + state: absent """ RETURN = """ @@ -110,7 +107,10 @@ diff.prepared: """ import collections +from copy import deepcopy + 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 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 @@ -149,26 +149,25 @@ def main(): state=dict(default='present', choices=['present', 'absent']), active=dict(default=True, type='bool') ) - aggregate_spec = element_spec.copy() + + aggregate_spec = deepcopy(element_spec) aggregate_spec['name'] = dict(required=True) 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( - aggregate=dict(type='list', elements='dict', options=aggregate_spec), - purge=dict(default=False, type='bool') + aggregate=dict(type='list', elements='dict', options=aggregate_spec, required_together=required_together) ) argument_spec.update(element_spec) argument_spec.update(junos_argument_spec) required_one_of = [['aggregate', 'name']] - required_together = [['name', 'vlan_id']] - mutually_exclusive = [['aggregate', 'name'], - ['aggregate', 'vlan_id'], - ['aggregate', 'description'], - ['aggregate', 'interfaces'], - ['aggregate', 'state'], - ['aggregate', 'active']] + mutually_exclusive = [['aggregate', 'name']] module = AnsibleModule(argument_spec=argument_spec, required_one_of=required_one_of, @@ -197,7 +196,13 @@ def main(): requests = list() 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() + validate_param_values(module, param_to_xpath_map, param=item) want = map_params_to_obj(module, param_to_xpath_map, param=item) diff --git a/lib/ansible/modules/network/junos/junos_vrf.py b/lib/ansible/modules/network/junos/junos_vrf.py index 45bd7d0a327..ce93a3c4ebf 100644 --- a/lib/ansible/modules/network/junos/junos_vrf.py +++ b/lib/ansible/modules/network/junos/junos_vrf.py @@ -55,11 +55,6 @@ options: JUNOS device. Ths list entries can either be the VRF name or a hash of VRF definitions and attributes. This argument is mutually 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: description: - Configures the state of the VRF definition @@ -78,7 +73,7 @@ requirements: - ncclient (>=v0.5.2) notes: - This module requires the netconf system service be enabled on - the remote device being managed + the remote device being managed. """ EXAMPLES = """ - name: Configure vrf configuration @@ -135,7 +130,6 @@ EXAMPLES = """ - ge-0/0/2 rd: 1.1.1.1:10 target: target:65514:113 - state: present - name: test-2 description: test-vrf-2 interfaces: @@ -143,7 +137,7 @@ EXAMPLES = """ - ge-0/0/5 rd: 2.2.2.2:10 target: target:65515:114 - state: present + state: present """ RETURN = """ @@ -164,7 +158,10 @@ diff.prepared: """ import collections +from copy import deepcopy + 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 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 @@ -190,25 +187,21 @@ def main(): active=dict(default=True, type='bool') ) - aggregate_spec = element_spec.copy() + 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( aggregate=dict(type='list', elements='dict', options=aggregate_spec), - purge=dict(default=False, type='bool') ) argument_spec.update(element_spec) argument_spec.update(junos_argument_spec) required_one_of = [['aggregate', 'name']] - mutually_exclusive = [['aggregate', 'name'], - ['aggregate', 'description'], - ['aggregate', 'rd'], - ['aggregate', 'interfaces'], - ['aggregate', 'target'], - ['aggregate', 'state'], - ['aggregate', 'active']] + mutually_exclusive = [['aggregate', 'name']] module = AnsibleModule(argument_spec=argument_spec, supports_check_mode=True, @@ -239,8 +232,12 @@ def main(): requests = list() 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' want = map_params_to_obj(module, param_to_xpath_map, param=item) diff --git a/lib/ansible/modules/network/system/net_logging.py b/lib/ansible/modules/network/system/net_logging.py index 9bab08d7df7..a07b7d96eeb 100644 --- a/lib/ansible/modules/network/system/net_logging.py +++ b/lib/ansible/modules/network/system/net_logging.py @@ -68,6 +68,28 @@ EXAMPLES = """ name: 1.1.1.1 facility: kernel 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 = """ diff --git a/test/integration/targets/junos_interface/tests/netconf/basic.yaml b/test/integration/targets/junos_interface/tests/netconf/basic.yaml index 674120ebd9b..23b53e2f1e9 100644 --- a/test/integration/targets/junos_interface/tests/netconf/basic.yaml +++ b/test/integration/targets/junos_interface/tests/netconf/basic.yaml @@ -1,7 +1,7 @@ --- - debug: msg="START junos_interface netconf/basic.yaml" -- name: setup - remove interface +- name: setup remove interface junos_interface: name: ge-0/0/1 description: test-interface @@ -169,8 +169,9 @@ - name: Set interface on aggregate junos_interface: aggregate: - - { name: ge-0/0/1, description: test-interface-1, speed: 1g, duplex: full, mtu: 512} - - { name: ge-0/0/2, description: test-interface-2, speed: 10m, duplex: full, mtu: 256} + - { name: ge-0/0/1, description: test-interface-1, speed: 1g, mtu: 512} + - { name: ge-0/0/2, description: test-interface-2, speed: 10m, mtu: 256} + duplex: full provider: "{{ netconf }}" register: result @@ -190,8 +191,9 @@ - name: Set interface on aggregate (idempotent) junos_interface: aggregate: - - { name: ge-0/0/1, description: test-interface-1, speed: 1g, duplex: full, mtu: 512} - - { name: ge-0/0/2, description: test-interface-2, speed: 10m, duplex: full, mtu: 256} + - { name: ge-0/0/1, description: test-interface-1, speed: 1g, mtu: 512 } + - { name: ge-0/0/2, description: test-interface-2, speed: 10m, mtu: 256 } + duplex: full provider: "{{ netconf }}" register: result @@ -202,8 +204,9 @@ - name: Disable interface on aggregate junos_interface: aggregate: - - { name: ge-0/0/1, description: test-interface-1, speed: 1g, duplex: full, mtu: 512, enabled: False} - - { name: ge-0/0/2, description: test-interface-2, speed: 10m, duplex: full, mtu: 256, enabled: False} + - name: ge-0/0/1 + - name: ge-0/0/2 + enabled: False provider: "{{ netconf }}" register: result @@ -215,8 +218,9 @@ - name: Enable interface on aggregate junos_interface: aggregate: - - { name: ge-0/0/1, description: test-interface-1, speed: 1g, duplex: full, mtu: 512, enabled: True} - - { name: ge-0/0/2, description: test-interface-2, speed: 10m, duplex: full, mtu: 256, enabled: True} + - name: ge-0/0/1 + - name: ge-0/0/2 + enabled: True provider: "{{ netconf }}" register: result @@ -228,8 +232,10 @@ - name: Deactivate interface configuration on aggregate junos_interface: aggregate: - - { name: ge-0/0/1, description: test-interface-1, speed: 1g, duplex: full, mtu: 512, active: False} - - { name: ge-0/0/2, description: test-interface-2, speed: 10m, duplex: full, mtu: 256, 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, mtu: 256 } + duplex: full + active: False provider: "{{ netconf }}" register: result @@ -242,8 +248,10 @@ - name: Activate interface configuration on aggregate junos_interface: aggregate: - - { name: ge-0/0/1, description: test-interface-1, speed: 1g, duplex: full, mtu: 512, active: True} - - { name: ge-0/0/2, description: test-interface-2, speed: 10m, duplex: full, mtu: 256, 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, mtu: 256 } + duplex: full + active: True provider: "{{ netconf }}" register: result @@ -256,8 +264,9 @@ - name: Delete interface on aggregate junos_interface: aggregate: - - { name: ge-0/0/1, description: test-interface-1, speed: 1g, duplex: full, mtu: 512, state: absent} - - { name: ge-0/0/2, description: test-interface-2, speed: 10m, duplex: full, mtu: 256, state: absent} + - name: ge-0/0/1 + - name: ge-0/0/2 + state: absent provider: "{{ netconf }}" register: result @@ -274,11 +283,12 @@ - result.diff.prepared | search("\- * mtu 256") - result.diff.prepared | search("\- *link-mode full-duplex") -- name: Delete interface aggregate (idempotent) +- name: Delete interface on aggregate (idempotent) junos_interface: aggregate: - - { name: ge-0/0/1, description: test-interface-1, speed: 1g, duplex: full, mtu: 512, state: absent} - - { name: ge-0/0/2, description: test-interface-2, speed: 10m, duplex: full, mtu: 256, state: absent} + - name: ge-0/0/1 + - name: ge-0/0/2 + state: absent provider: "{{ netconf }}" register: result diff --git a/test/integration/targets/junos_l3_interface/tests/netconf/basic.yaml b/test/integration/targets/junos_l3_interface/tests/netconf/basic.yaml index 917625449c7..57161b976a6 100644 --- a/test/integration/targets/junos_l3_interface/tests/netconf/basic.yaml +++ b/test/integration/targets/junos_l3_interface/tests/netconf/basic.yaml @@ -159,11 +159,10 @@ - name: ge-0/0/1 ipv4: 1.1.1.1 ipv6: fd5d:12c9:2201:1::1 - active: True - name: ge-0/0/2 ipv4: 2.2.2.2 ipv6: fd5d:12c9:2201:2::2 - active: True + active: True provider: "{{ netconf }}" register: result @@ -177,11 +176,10 @@ - name: ge-0/0/1 ipv4: 1.1.1.1 ipv6: fd5d:12c9:2201:1::1 - active: False - name: ge-0/0/2 ipv4: 2.2.2.2 ipv6: fd5d:12c9:2201:2::2 - active: False + active: False provider: "{{ netconf }}" register: result @@ -199,11 +197,10 @@ - name: ge-0/0/1 ipv4: 1.1.1.1 ipv6: fd5d:12c9:2201:1::1 - active: True - name: ge-0/0/2 ipv4: 2.2.2.2 ipv6: fd5d:12c9:2201:2::2 - active: True + active: True provider: "{{ netconf }}" register: result @@ -221,11 +218,10 @@ - name: ge-0/0/1 ipv4: 1.1.1.1 ipv6: fd5d:12c9:2201:1::1 - state: absent - name: ge-0/0/2 ipv4: 2.2.2.2 ipv6: fd5d:12c9:2201:2::2 - state: absent + state: absent provider: "{{ netconf }}" register: result @@ -247,11 +243,10 @@ - name: ge-0/0/1 ipv4: 1.1.1.1 ipv6: fd5d:12c9:2201:1::1 - state: absent - name: ge-0/0/2 ipv4: 2.2.2.2 ipv6: fd5d:12c9:2201:2::2 - state: absent + state: absent provider: "{{ netconf }}" register: result diff --git a/test/integration/targets/junos_logging/tests/netconf/basic.yaml b/test/integration/targets/junos_logging/tests/netconf/basic.yaml index 8777250dfe3..1a8a4c06834 100644 --- a/test/integration/targets/junos_logging/tests/netconf/basic.yaml +++ b/test/integration/targets/junos_logging/tests/netconf/basic.yaml @@ -324,8 +324,15 @@ - name: Deactivate file logging configuration using aggregate junos_logging: aggregate: - - {dest: file, name: test-1, facility: pfe, level: critical, active: False} - - {dest: file, name: test-2, facility: kernel, level: emergency, active: False} + - dest: file + name: test-1 + facility: pfe + level: critical + - dest: file + name: test-2 + facility: kernel + level: emergency + active: False provider: "{{ netconf }}" register: result @@ -340,8 +347,9 @@ - name: activate file logging configuration using aggregate junos_logging: aggregate: - - {dest: file, name: test-1, facility: pfe, level: critical, active: True} - - {dest: file, name: test-2, facility: kernel, level: emergency, active: True} + - { dest: file, name: test-1, facility: pfe, level: critical } + - { dest: file, name: test-2, facility: kernel, level: emergency } + active: True provider: "{{ netconf }}" register: result @@ -356,8 +364,9 @@ - name: Delete file logging using aggregate junos_logging: aggregate: - - {dest: file, name: test-1, facility: pfe, level: critical, state: absent} - - {dest: file, name: test-2, facility: kernel, level: emergency, state: absent} + - { dest: file, name: test-1, facility: pfe, level: critical } + - { dest: file, name: test-2, facility: kernel, level: emergency } + state: absent provider: "{{ netconf }}" register: result @@ -372,8 +381,9 @@ - name: Delete file logging using aggregate (idempotent) junos_logging: aggregate: - - {dest: file, name: test-1, facility: pfe, level: critical, state: absent} - - {dest: file, name: test-2, facility: kernel, level: emergency, state: absent} + - { dest: file, name: test-1, facility: pfe, level: critical } + - { dest: file, name: test-2, facility: kernel, level: emergency } + state: absent provider: "{{ netconf }}" register: result diff --git a/test/integration/targets/junos_static_route/tests/netconf/basic.yaml b/test/integration/targets/junos_static_route/tests/netconf/basic.yaml index c3df57c840e..fdd7460f268 100644 --- a/test/integration/targets/junos_static_route/tests/netconf/basic.yaml +++ b/test/integration/targets/junos_static_route/tests/netconf/basic.yaml @@ -144,15 +144,17 @@ - name: Setup static route for aggegrate junos_static_route: aggregate: - - {address: 4.4.4.0/24, state: absent} - - {address: 5.5.5.0/24, state: absent} + - address: 4.4.4.0/24 + - address: 5.5.5.0/24 + state: absent provider: "{{ netconf }}" - name: Confgiure static route using aggegrate junos_static_route: 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: 5.5.5.0/24, next_hop: 6.6.6.6, preference: 11, qualified_next_hop: 7.7.7.7, qualified_preference: 12} + - {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: 30 provider: "{{ netconf }}" register: result @@ -167,14 +169,16 @@ - result.diff.prepared | search("\+ *route 5.5.5.0/24") - 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("\+ *preference 12") + - result.diff.prepared | search("\+ *preference 30") - result.diff.prepared | search("\+ *preference 11") - name: Deactivate static route configuration using aggegrate junos_static_route: 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: 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: 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: 30 + active: False provider: "{{ netconf }}" register: result @@ -191,8 +195,10 @@ - name: Activate static route configuration using aggegrate junos_static_route: 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: 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: 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: 30 + active: True provider: "{{ netconf }}" register: result @@ -209,8 +215,9 @@ - name: Delete static route configuration using aggegrate junos_static_route: aggregate: - - {address: 4.4.4.0/24, state: absent} - - {address: 5.5.5.0/24, state: absent} + - address: 4.4.4.0/24 + - address: 5.5.5.0/24 + state: absent provider: "{{ netconf }}" register: result @@ -225,14 +232,15 @@ - result.diff.prepared | search("\- *route 5.5.5.0/24") - 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("\- *preference 12") + - result.diff.prepared | search("\- *preference 30") - result.diff.prepared | search("\- *preference 11") - name: Delete static route configuration using aggegrate (idempotent) junos_static_route: aggregate: - - {address: 4.4.4.0/24, state: absent} - - {address: 5.5.5.0/24, state: absent} + - address: 4.4.4.0/24 + - address: 5.5.5.0/24 + state: absent provider: "{{ netconf }}" register: result diff --git a/test/integration/targets/junos_vlan/tests/netconf/basic.yaml b/test/integration/targets/junos_vlan/tests/netconf/basic.yaml index 8d845dbfa6b..72815208aef 100644 --- a/test/integration/targets/junos_vlan/tests/netconf/basic.yaml +++ b/test/integration/targets/junos_vlan/tests/netconf/basic.yaml @@ -106,15 +106,18 @@ - name: Setup vlan configuration for aggregate junos_vlan: aggregate: - - { vlan_id: 159, name: test_vlan_1, state: absent } - - { vlan_id: 160, name: test_vlan_2, state: absent } + - vlan_id: 159 + name: test_vlan_1 + - vlan_id: 160 + name: test_vlan_2 + state: absent provider: "{{ netconf }}" - name: Create vlan configuration using aggregate junos_vlan: aggregate: - - { vlan_id: 159, name: test_vlan_1, description: test vlan-1, state: present } - - { vlan_id: 160, name: test_vlan_2, description: test vlan-2, state: present } + - { vlan_id: 159, name: test_vlan_1, description: test vlan-1 } + - { vlan_id: 160, name: test_vlan_2, description: test vlan-2 } provider: "{{ netconf }}" register: result @@ -129,8 +132,9 @@ - name: Deactivate vlan configuration using aggregate junos_vlan: aggregate: - - { vlan_id: 159, name: test_vlan_1, description: test vlan-1, active: False } - - { vlan_id: 160, name: test_vlan_2, description: test vlan-2, 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 provider: "{{ netconf }}" register: result @@ -143,8 +147,9 @@ - name: activate vlan configuration using aggregate junos_vlan: aggregate: - - { vlan_id: 159, name: test_vlan_1, description: test vlan-1, active: True } - - { vlan_id: 160, name: test_vlan_2, description: test vlan-2, 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 provider: "{{ netconf }}" register: result @@ -157,8 +162,11 @@ - name: Delete vlan configuration using aggregate junos_vlan: aggregate: - - { vlan_id: 159, name: test_vlan_1, state: absent } - - { vlan_id: 160, name: test_vlan_2, state: absent } + - vlan_id: 159 + name: test_vlan_1 + - vlan_id: 160 + name: test_vlan_2 + state: absent provider: "{{ netconf }}" register: result diff --git a/test/integration/targets/junos_vrf/tests/netconf/basic.yaml b/test/integration/targets/junos_vrf/tests/netconf/basic.yaml index c1ced7bcb21..1dd552116d3 100644 --- a/test/integration/targets/junos_vrf/tests/netconf/basic.yaml +++ b/test/integration/targets/junos_vrf/tests/netconf/basic.yaml @@ -172,9 +172,8 @@ junos_vrf: aggregate: - name: test-1 - state: absent - name: test-2 - state: absent + state: absent provider: "{{ netconf }}" register: result @@ -188,7 +187,6 @@ - ge-0/0/2 rd: 1.1.1.1:10 target: target:65514:113 - state: present - name: test-2 description: test-vrf-2 interfaces: @@ -196,7 +194,6 @@ - ge-0/0/5 rd: 2.2.2.2:10 target: target:65515:114 - state: present provider: "{{ netconf }}" register: result @@ -228,8 +225,6 @@ - ge-0/0/2 rd: 1.1.1.1:10 target: target:65514:113 - state: present - active: False - name: test-2 description: test-vrf-2 interfaces: @@ -237,8 +232,7 @@ - ge-0/0/5 rd: 2.2.2.2:10 target: target:65515:114 - state: present - active: False + active: False provider: "{{ netconf }}" register: result @@ -266,8 +260,6 @@ - ge-0/0/2 rd: 1.1.1.1:10 target: target:65514:113 - state: present - active: True - name: test-2 description: test-vrf-2 interfaces: @@ -275,8 +267,7 @@ - ge-0/0/5 rd: 2.2.2.2:10 target: target:65515:114 - state: present - active: True + active: True provider: "{{ netconf }}" register: result @@ -298,9 +289,8 @@ junos_vrf: aggregate: - name: test-1 - state: absent - name: test-2 - state: absent + state: absent provider: "{{ netconf }}" register: result @@ -326,9 +316,8 @@ junos_vrf: aggregate: - name: test-1 - state: absent - name: test-2 - state: absent + state: absent provider: "{{ netconf }}" register: result diff --git a/test/integration/targets/net_interface/tests/junos/basic.yaml b/test/integration/targets/net_interface/tests/junos/basic.yaml index 4da47cf747a..e158cb3fc3b 100644 --- a/test/integration/targets/net_interface/tests/junos/basic.yaml +++ b/test/integration/targets/net_interface/tests/junos/basic.yaml @@ -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: name: ge-0/0/1 description: test-interface @@ -74,17 +74,10 @@ provider: "{{ netconf }}" register: result -- name: Get running configuration - junos_rpc: - rpc: get-configuration - provider: "{{ netconf }}" - register: config - - assert: that: - "result.changed == true" - result.diff.prepared | search("\+ *disable") - - "'ge-0/0/1' in config.xml" - name: Enable interface net_interface: @@ -94,17 +87,10 @@ provider: "{{ netconf }}" register: result -- name: Get running configuration - junos_rpc: - rpc: get-configuration - provider: "{{ netconf }}" - register: config - - assert: that: - "result.changed == true" - result.diff.prepared | search("\- *disable") - - "'ge-0/0/1' in config.xml" - name: Delete interface net_interface: @@ -142,8 +128,9 @@ - name: Set interface on aggregate net_interface: aggregate: - - { name: ge-0/0/1, description: test-interface-1, speed: 1g, duplex: full, mtu: 512} - - { name: ge-0/0/2, description: test-interface-2, speed: 10m, duplex: full, mtu: 256} + - { name: ge-0/0/1, description: test-interface-1, speed: 1g, mtu: 512} + - { name: ge-0/0/2, description: test-interface-2, speed: 10m, mtu: 256} + duplex: full provider: "{{ netconf }}" register: result @@ -163,8 +150,9 @@ - name: Set interface on aggregate (idempotent) net_interface: aggregate: - - { name: ge-0/0/1, description: test-interface-1, speed: 1g, duplex: full, mtu: 512} - - { name: ge-0/0/2, description: test-interface-2, speed: 10m, duplex: full, mtu: 256} + - { name: ge-0/0/1, description: test-interface-1, speed: 1g, mtu: 512 } + - { name: ge-0/0/2, description: test-interface-2, speed: 10m, mtu: 256 } + duplex: full provider: "{{ netconf }}" register: result @@ -175,8 +163,9 @@ - name: Disable interface on aggregate net_interface: aggregate: - - { name: ge-0/0/1, description: test-interface-1, speed: 1g, duplex: full, mtu: 512, enabled: False} - - { name: ge-0/0/2, description: test-interface-2, speed: 10m, duplex: full, mtu: 256, enabled: False} + - name: ge-0/0/1 + - name: ge-0/0/2 + enabled: False provider: "{{ netconf }}" register: result @@ -188,8 +177,9 @@ - name: Enable interface on aggregate net_interface: aggregate: - - { name: ge-0/0/1, description: test-interface-1, speed: 1g, duplex: full, mtu: 512, enabled: True} - - { name: ge-0/0/2, description: test-interface-2, speed: 10m, duplex: full, mtu: 256, enabled: True} + - name: ge-0/0/1 + - name: ge-0/0/2 + enabled: True provider: "{{ netconf }}" register: result @@ -201,8 +191,9 @@ - name: Delete interface on aggregate net_interface: aggregate: - - { name: ge-0/0/1, description: test-interface-1, speed: 1g, duplex: full, mtu: 512, state: absent} - - { name: ge-0/0/2, description: test-interface-2, speed: 10m, duplex: full, mtu: 256, state: absent} + - { name: ge-0/0/1, description: test-interface-1 } + - { name: ge-0/0/2, description: test-interface-2 } + state: absent provider: "{{ netconf }}" register: result @@ -219,11 +210,12 @@ - result.diff.prepared | search("\- * mtu 256") - result.diff.prepared | search("\- *link-mode full-duplex") -- name: Delete interface aggregate (idempotent) +- name: Delete interface on aggregate (idempotent) net_interface: aggregate: - - { name: ge-0/0/1, description: test-interface-1, speed: 1g, duplex: full, mtu: 512, state: absent} - - { name: ge-0/0/2, description: test-interface-2, speed: 10m, duplex: full, mtu: 256, state: absent} + - name: ge-0/0/1 + - name: ge-0/0/2 + state: absent provider: "{{ netconf }}" register: result diff --git a/test/integration/targets/net_l3_interface/tests/junos/basic.yaml b/test/integration/targets/net_l3_interface/tests/junos/basic.yaml index 4e4dcb65903..6b1f2c4e4f0 100644 --- a/test/integration/targets/net_l3_interface/tests/junos/basic.yaml +++ b/test/integration/targets/net_l3_interface/tests/junos/basic.yaml @@ -29,8 +29,8 @@ - "result.changed == true" - "'1.1.1.1/32' in config.xml" - "'fd5d:12c9:2201:1::1/128' in config.xml" - - "'+ address 1.1.1.1/32;' in result.diff.prepared" - - "'+ address fd5d:12c9:2201:1::1/128;' in result.diff.prepared" + - result.diff.prepared | search("\+ *address 1.1.1.1/32") + - result.diff.prepared | search("\+ *address fd5d:12c9:2201:1::1/128") - name: Configure interface address (idempotent) net_l3_interface: @@ -65,8 +65,8 @@ - "result.changed == true" - "'1.1.1.1/32' not in config.xml" - "'fd5d:12c9:2201:1::1/128' not in config.xml" - - "'- address 1.1.1.1/32;' in result.diff.prepared" - - "'- address fd5d:12c9:2201:1::1/128;' in result.diff.prepared" + - result.diff.prepared | search("\- *address 1.1.1.1/32") + - result.diff.prepared | search("\- *address fd5d:12c9:2201:1::1/128") - name: Delete interface address (idempotent) net_l3_interface: @@ -129,11 +129,10 @@ - name: ge-0/0/1 ipv4: 1.1.1.1 ipv6: fd5d:12c9:2201:1::1 - active: True - name: ge-0/0/2 ipv4: 2.2.2.2 ipv6: fd5d:12c9:2201:2::2 - active: True + active: True provider: "{{ netconf }}" register: result @@ -147,11 +146,10 @@ - name: ge-0/0/1 ipv4: 1.1.1.1 ipv6: fd5d:12c9:2201:1::1 - state: absent - name: ge-0/0/2 ipv4: 2.2.2.2 ipv6: fd5d:12c9:2201:2::2 - state: absent + state: absent provider: "{{ netconf }}" register: result @@ -173,11 +171,10 @@ - name: ge-0/0/1 ipv4: 1.1.1.1 ipv6: fd5d:12c9:2201:1::1 - state: absent - name: ge-0/0/2 ipv4: 2.2.2.2 ipv6: fd5d:12c9:2201:2::2 - state: absent + state: absent provider: "{{ netconf }}" register: result diff --git a/test/integration/targets/net_logging/tests/junos/basic.yaml b/test/integration/targets/net_logging/tests/junos/basic.yaml index 41b14d88191..7e10cf3d490 100644 --- a/test/integration/targets/net_logging/tests/junos/basic.yaml +++ b/test/integration/targets/net_logging/tests/junos/basic.yaml @@ -126,8 +126,14 @@ - name: Configure file logging using aggregate net_logging: aggregate: - - {dest: file, name: test-1, facility: pfe, level: critical, active: True} - - {dest: file, name: test-2, facility: kernel, level: emergency, active: True} + - dest: file + name: test-1 + facility: pfe + level: critical + - dest: file + name: test-2 + facility: kernel + level: emergency provider: "{{ netconf }}" register: result @@ -142,8 +148,15 @@ - name: Delete file logging using aggregate net_logging: aggregate: - - {dest: file, name: test-1, facility: pfe, level: critical, state: absent} - - {dest: file, name: test-2, facility: kernel, level: emergency, state: absent} + - dest: file + name: test-1 + facility: pfe + level: critical + - dest: file + name: test-2 + facility: kernel + level: emergency + state: absent provider: "{{ netconf }}" register: result @@ -154,3 +167,22 @@ - result.diff.prepared | search("\- *pfe critical") - result.diff.prepared | search("\- *file test-2") - 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' diff --git a/test/integration/targets/net_vlan/tests/junos/basic.yaml b/test/integration/targets/net_vlan/tests/junos/basic.yaml index bae9be7561d..a05d8755bc6 100644 --- a/test/integration/targets/net_vlan/tests/junos/basic.yaml +++ b/test/integration/targets/net_vlan/tests/junos/basic.yaml @@ -62,15 +62,18 @@ - name: Setup vlan configuration for aggregate net_vlan: aggregate: - - { vlan_id: 159, name: test_vlan_1, state: absent } - - { vlan_id: 160, name: test_vlan_2, state: absent } + - vlan_id: 159 + name: test_vlan_1 + - vlan_id: 160 + name: test_vlan_2 + state: absent provider: "{{ netconf }}" - name: Create vlan configuration using aggregate net_vlan: aggregate: - - { vlan_id: 159, name: test_vlan_1, description: test vlan-1, state: present } - - { vlan_id: 160, name: test_vlan_2, description: test vlan-2, state: present } + - { vlan_id: 159, name: test_vlan_1, description: test vlan-1 } + - { vlan_id: 160, name: test_vlan_2, description: test vlan-2 } provider: "{{ netconf }}" register: result @@ -83,10 +86,13 @@ - result.diff.prepared | search("\+ *vlan-id 160") - name: Delete vlan configuration using aggregate - junos_vlan: + net_vlan: aggregate: - - { vlan_id: 159, name: test_vlan_1, state: absent } - - { vlan_id: 160, name: test_vlan_2, state: absent } + - vlan_id: 159 + name: test_vlan_1 + - vlan_id: 160 + name: test_vlan_2 + state: absent provider: "{{ netconf }}" register: result @@ -99,10 +105,13 @@ - result.diff.prepared | search("\- *vlan-id 160") - name: Delete vlan configuration using aggregate (idempotent) - junos_vlan: + net_vlan: aggregate: - - { vlan_id: 159, name: test_vlan_1, state: absent } - - { vlan_id: 160, name: test_vlan_2, state: absent } + - vlan_id: 159 + name: test_vlan_1 + - vlan_id: 160 + name: test_vlan_2 + state: absent provider: "{{ netconf }}" register: result diff --git a/test/integration/targets/net_vrf/tests/junos/basic.yaml b/test/integration/targets/net_vrf/tests/junos/basic.yaml index 05967f8d980..996538fba9b 100644 --- a/test/integration/targets/net_vrf/tests/junos/basic.yaml +++ b/test/integration/targets/net_vrf/tests/junos/basic.yaml @@ -121,9 +121,8 @@ net_vrf: aggregate: - name: test-1 - state: absent - name: test-2 - state: absent + state: absent provider: "{{ netconf }}" register: result @@ -137,7 +136,6 @@ - ge-0/0/2 rd: 1.1.1.1:10 target: target:65514:113 - state: present - name: test-2 description: test-vrf-2 interfaces: @@ -145,7 +143,6 @@ - ge-0/0/5 rd: 2.2.2.2:10 target: target:65515:114 - state: present provider: "{{ netconf }}" register: result @@ -171,9 +168,8 @@ net_vrf: aggregate: - name: test-1 - state: absent - name: test-2 - state: absent + state: absent provider: "{{ netconf }}" register: result @@ -199,9 +195,8 @@ net_vrf: aggregate: - name: test-1 - state: absent - name: test-2 - state: absent + state: absent provider: "{{ netconf }}" register: result