Repository: ansible/ansible-modules-core

Issue:
nxos_interface depends on nxos_feature which doesn't work on Nexus 7000
##### ISSUE TYPE
- Bug Report
##### COMPONENT NAME

nxos_interface
##### ANSIBLE VERSION

<!--- Paste verbatim output from “ansible --version” between quotes below -->

```
ansible 2.2.0
  config file = /vagrant/Ansible/Networking/ansible.cfg
  configured module search path = Default w/o overrides
```
##### OS / ENVIRONMENT

Ansible: Ubuntu
Remote: NXOSv (VIRL) running NX-OS 7.2(0)D1
##### SUMMARY

nxos_interface uses nxos_feature when asked to configure VLAN interfaces. nxos_feature fails on Nexus 7000 or Titanium-based NXOSv. It would be nice if the nxos_interface module would survive the nxos_feature failure and try to configure the interfaces anyway (or report problems based on nxos_feature results when available).

As an aside, it's possible to configure a loopback interface on Nexus 7000 (doesn't invoke features check), but not a VLAN interface.
##### STEPS TO REPRODUCE

Use this playbook on Nexus 7000 or Titanium-based NXOSv (VIRL)

```

---
- hosts: switch.lab.local
  tasks:
  - nxos_interface:
      provider: "{{nxapi}}"
      interface: "Vlan100"
      admin_state: up
```

<!--- You can also paste gist.github.com links for larger files -->
##### ACTUAL RESULTS

<!--- What actually happened? If possible run with extra verbosity (-vvvv) -->

<!--- Paste verbatim command output between quotes below -->

```
Using module file /usr/local/lib/python2.7/dist-packages/ansible-2.2.0-py2.7.egg/ansible/modules/core/network/nxos/nxos_interface.py
<s1.lab.local> ESTABLISH LOCAL CONNECTION FOR USER: vagrant
<s1.lab.local> EXEC /bin/sh -c '( umask 77 && mkdir -p "` echo $HOME/.ansible/tmp/ansible-tmp-1470989697.85-80179865048081 `" && echo ansible-tmp-1470989697.85-80179865048081="` echo $HOME/.ansible/tmp/ansible-tmp-1470989697.85-80179865048081 `" ) && sleep 0'
<s1.lab.local> PUT /tmp/tmpe3G4xT TO /home/vagrant/.ansible/tmp/ansible-tmp-1470989697.85-80179865048081/nxos_interface.py
<s1.lab.local> EXEC /bin/sh -c 'chmod -R u+x /home/vagrant/.ansible/tmp/ansible-tmp-1470989697.85-80179865048081/ && sleep 0'
<s1.lab.local> EXEC /bin/sh -c '/usr/bin/python /home/vagrant/.ansible/tmp/ansible-tmp-1470989697.85-80179865048081/nxos_interface.py; rm -rf "/home/vagrant/.ansible/tmp/ansible-tmp-1470989697.85-80179865048081/" > /dev/null 2>&1 && sleep 0'
fatal: [s1.lab.local]: FAILED! => {
    "changed": false,
    "clierror": "Feature Name          Instance  State   \n--------------------  --------  --------\nbfd                   1         disabled\nbfd_app               1         disabled\nbgp                   1         enabled \nbulkstat              1         disabled\ncable-management      1         disabled\ncts                   1         disabled\ndhcp                  1         disabled\ndot1x                 1         disabled\neigrp                 1         disabled\neigrp                 2         disabled\neigrp                 3         disabled\neigrp                 4         disabled\neigrp                 5         disabled\neigrp                 6         disabled\neigrp                 7         disabled\neigrp                 8         disabled\neigrp                 9         disabled\neigrp                 10        disabled\neigrp                 11        disabled\neigrp                 12        disabled\neigrp                 13        disabled\neigrp                 14        disabled\neigrp                 15        disabled\neigrp                 16        disabled\neth_port_sec          1         disabled\nevb                   1         disabled\nevc                   1         disabled\nevmed                 1         disabled\nevpn                  1         disabled\nfabric-access         1         disabled\nfabric_mcast          1         disabled\nglbp                  1         disabled\nhsrp_engine           1         disabled\ninterface-vlan        1         enabled \nisis                  1         disabled\nisis                  2         disabled\nisis                  3         disabled\nisis                  4         disabled\nisis                  5         disabled\nisis                  6         disabled\nisis                  7         disabled\nisis                  8         disabled\nisis                  9         disabled\nisis                  10        disabled\nisis                  11        disabled\nisis                  12        disabled\nisis                  13        disabled\nisis                  14        disabled\nisis                  15        disabled\nisis                  16        disabled\nitd                   1         disabled\nldap                  1         disabled\nlisp                  1         disabled\nlldp                  1         disabled\nmsdp                  1         disabled\nmvrp                  1         disabled\nnetflow               1         disabled\nnve                   1         disabled\nnxapi                 1         enabled \nonep                  1         disabled\nospf                  1         enabled \nospf                  2         enabled (not-running)\nospf                  3         enabled (not-running)\nospf                  4         enabled (not-running)\nospf                  5         enabled (not-running)\nospf                  6         enabled (not-running)\nospf                  7         enabled (not-running)\nospf                  8         enabled (not-running)\nospf                  9         enabled (not-running)\nospf                  10        enabled (not-running)\nospf                  11        enabled (not-running)\nospf                  12        enabled (not-running)\nospf                  13        enabled (not-running)\nospf                  14        enabled (not-running)\nospf                  15        enabled (not-running)\nospf                  16        enabled (not-running)\nospfv3                1         disabled\nospfv3                2         disabled\nospfv3                3         disabled\nospfv3                4         disabled\nospfv3                5         disabled\nospfv3                6         disabled\nospfv3                7         disabled\nospfv3                8         disabled\nospfv3                9         disabled\nospfv3                10        disabled\nospfv3                11        disabled\nospfv3                12        disabled\nospfv3                13        disabled\nospfv3                14        disabled\nospfv3                15        disabled\nospfv3                16        disabled\notv                   1         disabled\npbr                   1         disabled\npim                   1         disabled\npim6                  1         disabled\npoap                  1         disabled\npong                  1         disabled\nprivate-vlan          1         disabled\nprivilege             1         disabled\nptp                   1         disabled\nrip                   1         disabled\nrip                   2         disabled\nrip                   3         disabled\nrip                   4         disabled\nrise                  1         disabled\nscheduler             1         disabled\nscpServer             1         disabled\nsftpServer            1         disabled\nsla_responder         1         disabled\nsla_sender            1         disabled\nsshServer             1         enabled \ntacacs                1         disabled\ntelnetServer          1         enabled \ntunnel                1         disabled\nvni                   1         disabled\nvnseg_vlan            1         disabled\nvpc                   1         disabled\nvrrp                  1         disabled\nvrrpv3                1         disabled\nvtp                   1         disabled\nwccp                  1         disabled\n",
    "code": "501",
    "failed": true,
    "input": "show feature",
    "invocation": {
        "module_args": {
            "admin_state": "up",
            "description": null,
            "host": "s1.lab.local",
            "interface": "Vlan100",
            "mode": null,
            "password": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER",
            "port": null,
            "provider": {
                "host": "s1.lab.local",
                "password": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER",
                "transport": "nxapi",
                "username": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER"
            },
            "ssh_keyfile": null,
            "state": "present",
            "timeout": 10,
            "transport": "nxapi",
            "url_password": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER",
            "url_username": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER",
            "use_ssl": false,
            "username": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER",
            "validate_certs": true
        },
        "module_name": "nxos_interface"
    },
    "msg": "Structured output unsupported"
}
```



Discussion:
<!-- @ipspace: Thanks for filing this bug report! -->

@privateip, @GGabriele, @gundalow, ping. This issue is waiting on your response.
[click here for bot help](https://github.com/ansible/ansibullbot/blob/master/ISSUE_HELP.md)

<!--- boilerplate: issue_bug_new --->


Resolving patch:
diff --git a/network/nxos/nxos_interface.py b/network/nxos/nxos_interface.py
--- a/network/nxos/nxos_interface.py
+++ b/network/nxos/nxos_interface.py
@@ -157,33 +157,6 @@ def is_default_interface(interface, module):
         return 'DNE'
 
 
-def get_available_features(feature, module):
-    available_features = {}
-    command = 'show feature'
-    body = execute_show_command(command, module)
-
-    try:
-        body = body[0]['TABLE_cfcFeatureCtrlTable']['ROW_cfcFeatureCtrlTable']
-    except (TypeError, IndexError):
-        return available_features
-
-    for each_feature in body:
-        feature = each_feature['cfcFeatureCtrlName2']
-        state = each_feature['cfcFeatureCtrlOpStatus2']
-
-        if 'enabled' in state:
-            state = 'enabled'
-
-        if feature not in available_features.keys():
-            available_features[feature] = state
-        else:
-            if (available_features[feature] == 'disabled' and
-                    state == 'enabled'):
-                available_features[feature] = state
-
-    return available_features
-
-
 def get_interface_type(interface):
     """Gets the type of interface
 
@@ -626,15 +599,6 @@ def main():
     if normalized_interface == 'Vlan1' and state == 'absent':
         module.fail_json(msg='ERROR: CANNOT REMOVE VLAN 1!')
 
-    if intf_type == 'svi':
-        feature = 'interface-vlan'
-        available_features = get_available_features(feature, module)
-        svi_state = available_features[feature]
-        if svi_state == 'disabled':
-            module.fail_json(
-                msg='SVI (interface-vlan) feature needs to be enabled first',
-            )
-
     if intf_type == 'unknown':
         module.fail_json(
             msg='unknown interface type found-1',


Test patch: