Repository: ansible/ansible

Issue:
ios_interface issue if port/host is not mentioned in play
<!---
Verify first that your issue/request is not already reported on GitHub.
Also test if the latest release, and master branch are affected too.
-->

##### ISSUE TYPE
<!--- Pick one below and delete the rest: -->
 - Bug Report

##### COMPONENT NAME
<!--- Name of the module/plugin/task/feature -->
ios_interface

##### ANSIBLE VERSION
<!--- Paste verbatim output from “ansible --version” between quotes below -->
```
2.4
```

##### CONFIGURATION
<!---
Mention any settings you have changed/added/removed in ansible.cfg
(or using the ANSIBLE_* environment variables).
-->

##### 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.
-->

##### SUMMARY
<!--- Explain the problem briefly -->

##### 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.
-->

<!--- Paste example playbooks or commands between quotes below -->
```yaml
  tasks:
  - name: State check
    ios_interface:
      name: Gi0/0
      neighbors:
      - port: eth0
```

<!--- You can also paste gist.github.com links for larger files -->

##### EXPECTED RESULTS
<!--- What did you expect to happen when running the steps above? -->
Should run sucessfully
##### ACTUAL RESULTS
<!--- What actually happened? If possible run with extra verbosity (-vvvv) -->

<!--- Paste verbatim command output between quotes below -->
```
The full traceback is:
Traceback (most recent call last):
  File "/var/folders/bp/pf3l672j2s79st6d4ps6q7200000gn/T/ansible_Y72p4h/ansible_module_ios_interface.py", line 465, in <module>
    main()
  File "/var/folders/bp/pf3l672j2s79st6d4ps6q7200000gn/T/ansible_Y72p4h/ansible_module_ios_interface.py", line 456, in main
    failed_conditions = check_declarative_intent_params(module, want, result)
  File "/var/folders/bp/pf3l672j2s79st6d4ps6q7200000gn/T/ansible_Y72p4h/ansible_module_ios_interface.py", line 389, in check_declarative_intent_params
    failed_conditions.append('host ' + item['host'])
TypeError: cannot concatenate 'str' and 'NoneType' objects
```



Discussion:
cc @privateip @rcarrillocruz
[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/ios/ios_interface.py b/lib/ansible/modules/network/ios/ios_interface.py
--- a/lib/ansible/modules/network/ios/ios_interface.py
+++ b/lib/ansible/modules/network/ios/ios_interface.py
@@ -385,10 +385,12 @@ def check_declarative_intent_params(module, want, result):
                             if item.startswith('Port Description:'):
                                 have_port.append(item.split(':')[1].strip())
             for item in want_neighbors:
-                if item['host'] not in have_host:
-                    failed_conditions.append('host ' + item['host'])
-                if item['port'] not in have_port:
-                    failed_conditions.append('port ' + item['port'])
+                host = item.get('host')
+                port = item.get('port')
+                if host and host not in have_host:
+                    failed_conditions.append('host ' + host)
+                if port and port not in have_port:
+                    failed_conditions.append('port ' + port)
     return failed_conditions
 
 


Test patch: