diff --git a/lib/ansible/modules/network/junos/junos_vlan.py b/lib/ansible/modules/network/junos/junos_vlan.py index 681d6cec3d..fc9f37be23 100644 --- a/lib/ansible/modules/network/junos/junos_vlan.py +++ b/lib/ansible/modules/network/junos/junos_vlan.py @@ -121,10 +121,11 @@ except ImportError: from xml.etree.ElementTree import tostring USE_PERSISTENT_CONNECTION = True +DEFAULT_DESCRIPTION = "configured by junos_vlan" def validate_vlan_id(value, module): - if not 1 <= value <= 4094: + if value and not 1 <= value <= 4094: module.fail_json(msg='vlan_id must be between 1 and 4094') @@ -144,7 +145,7 @@ def main(): element_spec = dict( name=dict(), vlan_id=dict(type='int'), - description=dict(), + description=dict(default=DEFAULT_DESCRIPTION), interfaces=dict(), state=dict(default='present', choices=['present', 'absent']), active=dict(default=True, type='bool') @@ -152,15 +153,12 @@ def main(): 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, required_together=required_together) + aggregate=dict(type='list', elements='dict', options=aggregate_spec) ) argument_spec.update(element_spec) @@ -171,7 +169,6 @@ def main(): module = AnsibleModule(argument_spec=argument_spec, required_one_of=required_one_of, - required_together=required_together, mutually_exclusive=mutually_exclusive, supports_check_mode=True) diff --git a/test/integration/targets/junos_vlan/tests/netconf/basic.yaml b/test/integration/targets/junos_vlan/tests/netconf/basic.yaml index 72815208ae..6b51859594 100644 --- a/test/integration/targets/junos_vlan/tests/netconf/basic.yaml +++ b/test/integration/targets/junos_vlan/tests/netconf/basic.yaml @@ -3,7 +3,6 @@ - name: setup - remove vlan junos_vlan: - vlan_id: 100 name: test-vlan description: test vlan state: absent @@ -117,7 +116,7 @@ junos_vlan: aggregate: - { vlan_id: 159, name: test_vlan_1, description: test vlan-1 } - - { vlan_id: 160, name: test_vlan_2, description: test vlan-2 } + - name: test_vlan_2 provider: "{{ netconf }}" register: result @@ -127,13 +126,13 @@ - result.diff.prepared | search("\+ *test_vlan_1") - result.diff.prepared | search("\+ *vlan-id 159") - result.diff.prepared | search("\+ *test_vlan_2") - - result.diff.prepared | search("\+ *vlan-id 160") + - result.diff.prepared | search("\+ *description \"configured by junos_vlan\"") - name: Deactivate vlan configuration using aggregate junos_vlan: aggregate: - { vlan_id: 159, name: test_vlan_1, description: test vlan-1 } - - { vlan_id: 160, name: test_vlan_2, description: test vlan-2 } + - name: test_vlan_2 active: False provider: "{{ netconf }}" register: result @@ -148,7 +147,7 @@ junos_vlan: aggregate: - { vlan_id: 159, name: test_vlan_1, description: test vlan-1 } - - { vlan_id: 160, name: test_vlan_2, description: test vlan-2 } + - name: test_vlan_2 active: True provider: "{{ netconf }}" register: result @@ -164,8 +163,7 @@ aggregate: - vlan_id: 159 name: test_vlan_1 - - vlan_id: 160 - name: test_vlan_2 + - name: test_vlan_2 state: absent provider: "{{ netconf }}" register: result @@ -176,13 +174,13 @@ - result.diff.prepared | search("\- *test_vlan_1") - result.diff.prepared | search("\- *vlan-id 159") - result.diff.prepared | search("\- *test_vlan_2") - - result.diff.prepared | search("\- *vlan-id 160") - name: Delete vlan configuration using aggregate (idempotent) 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 } + - name: test_vlan_2 + state: absent provider: "{{ netconf }}" register: result