Repository: ansible/ansible

Issue:
eos_vlan: Interfaces assigned to vlan do not show up if port is not live
##### ISSUE TYPE
 - Bug Report

##### COMPONENT NAME
eos_vlan
##### ANSIBLE VERSION
<!--- Paste verbatim output from "ansible --version" between quotes below -->
```
ansible 2.4.2.0
  config file = None
  configured module search path = [u'/Users/jlee/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/local/Cellar/ansible/2.4.2.0_1/libexec/lib/python2.7/site-packages/ansible
  executable location = /usr/local/bin/ansible
  python version = 2.7.14 (default, Sep 25 2017, 09:53:22) [GCC 4.2.1 Compatible Apple LLVM 9.0.0 (clang-900.0.37)]
```

##### CONFIGURATION
<!---
If using Ansible 2.4 or above, paste the results of "ansible-config dump --only-changed"
Otherwise, mention any settings you have changed/added/removed in ansible.cfg
(or using the ANSIBLE_* environment variables).
-->
```
DEFAULT_DEBUG(env: ANSIBLE_DEBUG) = True
```
##### OS / ENVIRONMENT
<!---
Mention the OS you are running Ansible from, and the OS you are
managing, or say "N/A" for anything that is not platform-specific.
Also mention the specific version of what you are trying to control,
e.g. if this is a network bug the version of firmware on the network device.
-->
N/A
##### SUMMARY
<!--- Explain the problem briefly -->
If a cable is not plugged into an interface on the switch, when attempting to assign the interface to vlan, the interface will not show up as an assigned interface on the vlan.

##### STEPS TO REPRODUCE
<!---
For bugs, show exactly how to reproduce the problem, using a minimal test-case.
For new features, show how the feature would be used.
-->
Ensure that nothing is connected to interface 5.
Assign interface 5 to vlan 1234
Playbook fails with error "Interface x does not exist
<!--- Paste example playbooks or commands between quotes below -->
```
    - eos_vlan:
        authorize: yes
        vlan_id: 1234
        name: "example_vlan"
        state: present
        provider: "{{ cli }}"
        interfaces:
          - Ethernet1
          - Ethernet2
          - Ethernet3
          - Ethernet4
          - Ethernet5

```

<!--- You can also paste gist.github.com links for larger files -->

##### EXPECTED RESULTS
<!--- What did you expect to happen when running the steps above? -->
Interface should successfully be assigned to a vlan

##### ACTUAL RESULTS
<!--- What actually happened? If possible run with extra verbosity (-vvvv) -->
ansible playbook error "interface x not assigned to vlan"

<!--- Paste verbatim command output between quotes below -->
```

```



Discussion:

Resolving patch:
diff --git a/lib/ansible/modules/network/eos/eos_vlan.py b/lib/ansible/modules/network/eos/eos_vlan.py
--- a/lib/ansible/modules/network/eos/eos_vlan.py
+++ b/lib/ansible/modules/network/eos/eos_vlan.py
@@ -199,24 +199,22 @@ def map_obj_to_commands(updates, module):
 
 def map_config_to_obj(module):
     objs = []
-    output = run_commands(module, ['show vlan'])
-    lines = output[0].strip().splitlines()[2:]
+    vlans = run_commands(module, ['show vlan conf | json'])
 
-    for l in lines:
-        splitted_line = re.split(r'\s{2,}', l.strip())
+    for vlan in vlans[0]['vlans']:
         obj = {}
-        obj['vlan_id'] = splitted_line[0]
-        obj['name'] = splitted_line[1]
-        obj['state'] = splitted_line[2]
+        obj['vlan_id'] = vlan
+        obj['name'] = vlans[0]['vlans'][vlan]['name']
+        obj['state'] = vlans[0]['vlans'][vlan]['status']
+        obj['interfaces'] = []
 
-        if obj['state'] == 'suspended':
-            obj['state'] = 'suspend'
+        interfaces = vlans[0]['vlans'][vlan]
 
-        obj['interfaces'] = []
-        if len(splitted_line) > 3:
+        for interface in interfaces['interfaces']:
+            obj['interfaces'].append(interface)
 
-            for i in splitted_line[3].split(','):
-                obj['interfaces'].append(i.strip().replace('Et', 'ethernet'))
+        if obj['state'] == 'suspended':
+            obj['state'] = 'suspend'
 
         objs.append(obj)
 


Test patch: