Repository: ansible/ansible

Issue:
ios_banner: KeyError: 'text' on state: absent
##### ISSUE TYPE
 - Bug Report

##### COMPONENT NAME
ios_banner

##### ANSIBLE VERSION
```
johnb@x260:~/git/ansible-inc/ansible-workspace-2/test/integration (devel)$ ansible --version
ansible 2.4.0 (devel d890167575) last updated 2017/04/05 17:20:37 (GMT +100)
  config file = 
  configured module search path = [u'/home/johnb/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /home/johnb/git/ansible-inc/ansible-workspace-2/lib/ansible
  executable location = /home/johnb/git/ansible-inc/ansible-workspace-2/bin/ansible
  python version = 2.7.12 (default, Nov 19 2016, 06:48:10) [GCC 5.4.0 20160609]

```

##### SUMMARY

##### STEPS TO REPRODUCE
```yaml
time ANSIBLE_PARAMIKO_LOOK_FOR_KEYS=False ANSIBLE_ROLES_PATH=targets  ansible-playbook -vvvvv  -i  inventory.network-jobarker  ios.yaml -u cisco -k
```

##### EXPECTED RESULTS

##### ACTUAL RESULTS
```yaml
TASK [ios_banner : remove login (idempotent)] ****************************************************************************************************************************************************************************************************
task path: /home/johnb/git/ansible-inc/ansible-workspace-2/test/integration/targets/ios_banner/tests/cli/basic-no-login.yaml:28
Using module file /home/johnb/git/ansible-inc/ansible-workspace-2/lib/ansible/modules/network/ios/ios_banner.py
<ios01> ESTABLISH LOCAL CONNECTION FOR USER: johnb
<ios01> EXEC /bin/sh -c 'echo ~ && sleep 0'
<ios01> EXEC /bin/sh -c '( umask 77 && mkdir -p "` echo /home/johnb/.ansible/tmp/ansible-tmp-1491409268.8-277228905646339 `" && echo ansible-tmp-1491409268.8-277228905646339="` echo /home/johnb/.ansible/tmp/ansible-tmp-1491409268.8-277228905646339 `" ) && sleep 0'
<ios01> PUT /tmp/tmpIkAI8j TO /home/johnb/.ansible/tmp/ansible-tmp-1491409268.8-277228905646339/ios_banner.py
<ios01> EXEC /bin/sh -c 'chmod u+x /home/johnb/.ansible/tmp/ansible-tmp-1491409268.8-277228905646339/ /home/johnb/.ansible/tmp/ansible-tmp-1491409268.8-277228905646339/ios_banner.py && sleep 0'
<ios01> EXEC /bin/sh -c 'python /home/johnb/.ansible/tmp/ansible-tmp-1491409268.8-277228905646339/ios_banner.py; rm -rf "/home/johnb/.ansible/tmp/ansible-tmp-1491409268.8-277228905646339/" > /dev/null 2>&1 && sleep 0'
The full traceback is:
Traceback (most recent call last):
  File "/tmp/ansible_Xjd4_i/ansible_module_ios_banner.py", line 175, in <module>
    main()
  File "/tmp/ansible_Xjd4_i/ansible_module_ios_banner.py", line 163, in main
    commands = map_obj_to_commands((want, have), module)
  File "/tmp/ansible_Xjd4_i/ansible_module_ios_banner.py", line 95, in map_obj_to_commands
    if state == 'absent' and have['text']:
KeyError: 'text'

fatal: [ios01]: FAILED! => {
    "changed": false, 
    "failed": true, 
    "module_stderr": "Traceback (most recent call last):\n  File \"/tmp/ansible_Xjd4_i/ansible_module_ios_banner.py\", line 175, in <module>\n    main()\n  File \"/tmp/ansible_Xjd4_i/ansible_module_ios_banner.py\", line 163, in main\n    commands = map_obj_to_commands((want, have), module)\n  File \"/tmp/ansible_Xjd4_i/ansible_module_ios_banner.py\", line 95, in map_obj_to_commands\n    if state == 'absent' and have['text']:\nKeyError: 'text'\n", 
    "module_stdout": "", 
    "msg": "MODULE FAILURE", 
    "rc": 0
}

```



Discussion:
cc @privateip
[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_banner.py b/lib/ansible/modules/network/ios/ios_banner.py
--- a/lib/ansible/modules/network/ios/ios_banner.py
+++ b/lib/ansible/modules/network/ios/ios_banner.py
@@ -92,7 +92,7 @@ def map_obj_to_commands(updates, module):
     want, have = updates
     state = module.params['state']
 
-    if state == 'absent' and have['text']:
+    if state == 'absent' and 'text' in have.keys() and have['text']:
         commands.append('no banner %s' % module.params['banner'])
 
     elif state == 'present':


Test patch: