Repository: ansible/ansible

Issue:
firewalld: clarify failure reason when not installed
##### ISSUE TYPE
 - Bug Report

##### COMPONENT NAME
firewalld

##### ANSIBLE VERSION
```
ansible 2.4.0.0
  config file = /home/duck/OSAS/community-cage-infra-ansible/ansible.cfg
  configured module search path = [u'/home/duck/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /home/duck/.local/lib/python2.7/site-packages/ansible
  executable location = /home/duck/.local/bin/ansible
  python version = 2.7.14 (default, Sep 17 2017, 18:50:44) [GCC 7.2.0]
```

##### CONFIGURATION
```
ANSIBLE_FORCE_COLOR(env: ANSIBLE_FORCE_COLOR) = True
ANSIBLE_SSH_ARGS(/home/duck/OSAS/community-cage-infra-ansible/ansible.cfg) = -o ControlMaster=auto -o ControlPersist=30m
ANSIBLE_SSH_PIPELINING(/home/duck/OSAS/community-cage-infra-ansible/ansible.cfg) = True
CACHE_PLUGIN(/home/duck/OSAS/community-cage-infra-ansible/ansible.cfg) = jsonfile
CACHE_PLUGIN_CONNECTION(/home/duck/OSAS/community-cage-infra-ansible/ansible.cfg) = ./facts_cache
CACHE_PLUGIN_TIMEOUT(/home/duck/OSAS/community-cage-infra-ansible/ansible.cfg) = 86400
DEFAULT_ACTION_PLUGIN_PATH(/home/duck/OSAS/community-cage-infra-ansible/ansible.cfg) = [u'/home/duck/OSAS/community-cage-infra-ansible/plugins/acti
DEFAULT_CALLBACK_PLUGIN_PATH(/home/duck/OSAS/community-cage-infra-ansible/ansible.cfg) = [u'/home/duck/OSAS/community-cage-infra-ansible/plugins/ca
DEFAULT_CONNECTION_PLUGIN_PATH(/home/duck/OSAS/community-cage-infra-ansible/ansible.cfg) = [u'/home/duck/OSAS/community-cage-infra-ansible/plugins/
DEFAULT_FILTER_PLUGIN_PATH(/home/duck/OSAS/community-cage-infra-ansible/ansible.cfg) = [u'/home/duck/OSAS/community-cage-infra-ansible/plugins/filt
DEFAULT_FORKS(/home/duck/OSAS/community-cage-infra-ansible/ansible.cfg) = 10
DEFAULT_GATHERING(/home/duck/OSAS/community-cage-infra-ansible/ansible.cfg) = smart
DEFAULT_HASH_BEHAVIOUR(/home/duck/OSAS/community-cage-infra-ansible/ansible.cfg) = merge
DEFAULT_HOST_LIST(/home/duck/OSAS/community-cage-infra-ansible/ansible.cfg) = [u'/home/duck/OSAS/community-cage-infra-ansible/hosts.yml']
DEFAULT_LOOKUP_PLUGIN_PATH(/home/duck/OSAS/community-cage-infra-ansible/ansible.cfg) = [u'/home/duck/OSAS/community-cage-infra-ansible/plugins/look
DEFAULT_MANAGED_STR(/home/duck/OSAS/community-cage-infra-ansible/ansible.cfg) = Ansible managed
DEFAULT_ROLES_PATH(/home/duck/OSAS/community-cage-infra-ansible/ansible.cfg) = [u'/home/duck/OSAS/community-cage-infra-ansible/roles']
DEFAULT_TIMEOUT(/home/duck/OSAS/community-cage-infra-ansible/ansible.cfg) = 40
DEFAULT_VARS_PLUGIN_PATH(/home/duck/OSAS/community-cage-infra-ansible/ansible.cfg) = [u'/home/duck/OSAS/community-cage-infra-ansible/plugins/vars']
DEFAULT_VAULT_PASSWORD_FILE(env: ANSIBLE_VAULT_PASSWORD_FILE) = /home/duck/.ansible_vault/cage.txt
ERROR_ON_MISSING_HANDLER(/home/duck/OSAS/community-cage-infra-ansible/ansible.cfg) = True
PERSISTENT_CONNECT_TIMEOUT(/home/duck/OSAS/community-cage-infra-ansible/ansible.cfg) = 1800
```

##### OS / ENVIRONMENT
The controller is on Debian unstable and the host is on Debian Stretch.

##### SUMMARY
On Debian firewalld is not installed by default and I forgot to install it in my rules. This module then fails, which is perfectly normal, but is unable to give an understandable reason. It would really help users to get a better message.

##### STEPS TO REPRODUCE
With this simple tasks:
```yaml
 - name: Open the firewall for {{ ssh_port }} using firewalld
   firewalld: port={{ ssh_port }}/tcp permanent=true state=enabled immediate=yes
```

<!--- You can also paste gist.github.com links for larger files -->

##### EXPECTED RESULTS
A proper error message telling me firewalld is missing or cannot be contacted.

##### ACTUAL RESULTS
I got this very cryptic message:
```
fatal: [projects.osci.io]: FAILED! => {"changed": false, "failed": true, "module_stderr": "Shared connection to 8.43.85.197 closed.\r\n", "module_stdout": "Traceback (most recent call last):\r\n  File \"/tmp/ansible_2zstha8x/ansible_module_firewalld.py\", line 937, in <module>\r\n    main()\r\n  File \"/tmp/ansible_2zstha8x/ansible_module_firewalld.py\", line 755, in main\r\n    % e\r\nNameError: name 'e' is not defined\r\n", "msg": "MODULE FAILURE", "rc": 0}
```



Discussion:
cc @maxamillion
[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/system/firewalld.py b/lib/ansible/modules/system/firewalld.py
--- a/lib/ansible/modules/system/firewalld.py
+++ b/lib/ansible/modules/system/firewalld.py
@@ -169,7 +169,7 @@
         fw.start()
         fw_offline = True
 
-except ImportError as e:
+except ImportError:
     import_failure = True
 
 
@@ -751,8 +751,7 @@ def main():
 
     if import_failure:
         module.fail_json(
-            msg='firewalld and its python 2 module are required for this module, version 2.0.11 or newer required (3.0.9 or newer for offline operations) \n %s'
-            % e
+            msg='firewalld and its python 2 module are required for this module, version 2.0.11 or newer required (3.0.9 or newer for offline operations)'
         )
 
     if fw_offline:


Test patch: