Repository: ansible/ansible

Issue:
nxos_vrf remove fails when vni is present
##### ISSUE TYPE
 - Bug Report

##### COMPONENT NAME
nxos_vrf

##### ANSIBLE VERSION
```
ansible 2.4.0 (devel 54cd641df4) last updated 2017/07/19 18:06:44 (GMT -400)
  config file = None
  configured module search path = [u'/root/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /root/p2/Projects/nxos_ansible/p1_ansible/lib/ansible
  executable location = /root/p2/Projects/nxos_ansible/p1_ansible/bin/ansible
  python version = 2.7.6 (default, Oct 26 2016, 20:30:19) [GCC 4.8.4]
```

##### CONFIGURATION
<!---
Mention any settings you have changed/added/removed in ansible.cfg
(or using the ANSIBLE_* environment variables).
-->

##### OS / ENVIRONMENT
cisco Nexus9000 C9396PX running 7.0(3)I7(1)

##### SUMMARY
When we try to delete vrf configuration with vni configuration present, it fails. The issue seems to be coming from NOT checking if the state == present when adding "no vni ..." to the commands.

##### STEPS TO REPRODUCE
playbook:

```
- block:
  - name: Ensure ntc VRF exists on switch
    nxos_vrf: &configure
      vrf: ntc
      admin_state: down
      vni: 5000
      rd: auto
      description: testing
      provider: "{{ cli }}"
    register: result

  - assert: &true
      that:
        - "result.changed == true"

  - name: "Conf Idempotence"
    nxos_vrf: *configure
    register: result

  - assert: &false
      that:
        - "result.changed == false"

  - name: Ensure ntc VRF does not exist on switch
    nxos_vrf: &remove
      vrf: ntc
      admin_state: down
      vni: 5000
      rd: auto
      description: testing
      state: absent
      provider: "{{ cli }}"
    register: result

  - assert: *true

  - name: "Remove Idempotence"
    nxos_vrf: *remove
    register: result

  - assert: *false

```

##### EXPECTED RESULTS
```
PLAY RECAP ********************************************************************************************************************************************
n9k.example.com          : ok=37   changed=5    unreachable=0    failed=0
```

##### ACTUAL RESULTS
```
TASK [nxos_vrf : Ensure ntc VRF does not exist on switch] *********************************************************************************************
fatal: [n9k.example.com]: FAILED! => {"changed": false, "failed": true, "msg": "no vni 5000\r\r\n                               ^\r\n% Invalid command at '^' marker.\r\n\rn9k.example.com(config)# "}
```



Discussion:
cc @GGabriele @jedelman8 @mikewiebe @privateip @rahushen @rcarrillocruz @trishnaguha
[click here for bot help](https://github.com/ansible/ansibullbot/blob/master/ISSUE_HELP.md)
<!--- boilerplate: notify --->

Resolving patch:
diff --git a/lib/ansible/modules/network/nxos/nxos_vrf.py b/lib/ansible/modules/network/nxos/nxos_vrf.py
--- a/lib/ansible/modules/network/nxos/nxos_vrf.py
+++ b/lib/ansible/modules/network/nxos/nxos_vrf.py
@@ -257,15 +257,15 @@ def main():
             command = get_commands_to_config_vrf(delta, vrf)
             commands.extend(command)
 
-    if commands:
+    if state == 'present' and commands:
         if proposed.get('vni'):
             if existing.get('vni') and existing.get('vni') != '':
                 commands.insert(1, 'no vni {0}'.format(existing['vni']))
 
-        if not module.check_mode:
-            load_config(module, commands)
-
+    if commands and not module.check_mode:
+        load_config(module, commands)
         results['changed'] = True
+
         if 'configure' in commands:
             commands.pop(0)
 


Test patch: