diff --git a/lib/ansible/modules/network/nxos/nxos_interface.py b/lib/ansible/modules/network/nxos/nxos_interface.py index 64b0c801cc6..cb683177c00 100644 --- a/lib/ansible/modules/network/nxos/nxos_interface.py +++ b/lib/ansible/modules/network/nxos/nxos_interface.py @@ -302,7 +302,7 @@ def normalize_interface(name): def _get_number(name): digits = '' for char in name: - if char.isdigit() or char == '/': + if char.isdigit() or char in '/.': digits += char return digits diff --git a/lib/ansible/modules/network/nxos/nxos_l3_interface.py b/lib/ansible/modules/network/nxos/nxos_l3_interface.py index 85968850f14..3fbd025b7d8 100644 --- a/lib/ansible/modules/network/nxos/nxos_l3_interface.py +++ b/lib/ansible/modules/network/nxos/nxos_l3_interface.py @@ -122,7 +122,6 @@ def map_obj_to_commands(updates, module): if command: command.append('exit') command.insert(0, 'interface {0}'.format(name)) - command.insert(1, 'no switchport') commands.extend(command) elif state == 'present' and obj_in_have: @@ -135,10 +134,8 @@ def map_obj_to_commands(updates, module): if command: command.append('exit') command.insert(0, 'interface {0}'.format(name)) - command.insert(1, 'no switchport') elif not ipv4 and not ipv6: command.append('interface {0}'.format(name)) - command.append('no switchport') commands.extend(command) return commands diff --git a/test/integration/targets/nxos_interface/tests/common/sub_int.yaml b/test/integration/targets/nxos_interface/tests/common/sub_int.yaml new file mode 100644 index 00000000000..27b1ccf19e9 --- /dev/null +++ b/test/integration/targets/nxos_interface/tests/common/sub_int.yaml @@ -0,0 +1,77 @@ +--- +- debug: msg="START connection={{ ansible_connection }} nxos_interface sub-interface test" +- debug: msg="Using provider={{ connection.transport }}" + when: ansible_connection == "local" + +- set_fact: testint="{{ nxos_int1 }}" + +- name: Setup - delete sub-interface + nxos_interface: &rm + name: "{{ testint }}.20" + state: absent + ignore_errors: yes + +- name: Setup - Ensure the interface is layer3 + nxos_interface: + name: "{{ testint }}" + mode: layer3 + +- name: Create sub-interface + nxos_interface: &sub_int + name: "{{ testint }}.20" + description: "sub-interface Configured by Ansible" + admin_state: up + mtu: 800 + provider: "{{ connection }}" + register: result + +- assert: + that: + - "result.changed == true" + +- name: Create sub-interface (Idempotence) + nxos_interface: *sub_int + register: result + +- assert: + that: + - "result.changed == false" + +- name: Make admin_state down + nxos_interface: &state_down + name: "{{ testint }}.20" + description: "sub-interface Configured by Ansible" + admin_state: down + mtu: 800 + provider: "{{ connection }}" + register: result + +- assert: + that: + - "result.changed == true" + +- name: Create sub-interface (Idempotence) + nxos_interface: *state_down + register: result + +- assert: + that: + - "result.changed == false" + +- name: Remove sub-interface + nxos_interface: *rm + register: result + +- assert: + that: + - "result.changed == true" + +- name: Remove sub-interface (Idempotence) + nxos_interface: *rm + register: result + +- assert: + that: + - "result.changed == false" + +- debug: msg="END connection={{ ansible_connection }} nxos_interface sub-interface test" diff --git a/test/integration/targets/nxos_l3_interface/tests/cli/sanity.yaml b/test/integration/targets/nxos_l3_interface/tests/cli/sanity.yaml index 0da11f07a1e..080aad6bfae 100644 --- a/test/integration/targets/nxos_l3_interface/tests/cli/sanity.yaml +++ b/test/integration/targets/nxos_l3_interface/tests/cli/sanity.yaml @@ -30,6 +30,14 @@ provider: "{{ cli }}" ignore_errors: yes +- name: Setup - Ensure interfaces are layer3 + nxos_interface: + aggregate: + - name: "{{ testint2 }}" + - name: "{{ testint3 }}" + mode: layer3 + provider: "{{ cli }}" + - name: Configure ipv4 address to interface nxos_l3_interface: &conf name: "{{ testint2 }}" diff --git a/test/integration/targets/nxos_l3_interface/tests/nxapi/sanity.yaml b/test/integration/targets/nxos_l3_interface/tests/nxapi/sanity.yaml index dd64379671e..e9e20fbe6b5 100644 --- a/test/integration/targets/nxos_l3_interface/tests/nxapi/sanity.yaml +++ b/test/integration/targets/nxos_l3_interface/tests/nxapi/sanity.yaml @@ -20,6 +20,14 @@ state: absent ignore_errors: yes +- name: Setup - Ensure interfaces are layer3 + nxos_interface: + aggregate: + - name: "{{ testint2 }}" + - name: "{{ testint3 }}" + mode: layer3 + provider: "{{ nxapi }}" + - name: Configure ipv4 address to interface nxos_l3_interface: &conf name: "{{ testint2 }}"