internlm/SWE-Fixer-Train-110K huggingface dataset:
Repository: ansible/ansible-modules-extras

Issue:
zabbix_host TypeError on host update without interfaces
I get the following exception when updating a host without specifying interfaces:

> An exception occurred during task execution. The full traceback is:
> Traceback (most recent call last):
>   File "/home/plldp/.ansible/tmp/ansible-tmp-1454663921.27-43711125456205/zabbix_host", line 2430, in <module>
>     main()
>   File "/home/plldp/.ansible/tmp/ansible-tmp-1454663921.27-43711125456205/zabbix_host", line 464, in main
>     exist_interfaces, zabbix_host_obj, proxy_id):
>   File "/home/plldp/.ansible/tmp/ansible-tmp-1454663921.27-43711125456205/zabbix_host", line 334, in check_all_properties
>     if self.check_interface_properties(exist_interfaces, interfaces):
>   File "/home/plldp/.ansible/tmp/ansible-tmp-1454663921.27-43711125456205/zabbix_host", line 293, in check_interface_properties
>     if len(interfaces) >= 1:
> TypeError: object of type 'NoneType' has no len()

I would suggest checking if interfaces is set. Perhaps something like this in zabbix-host.py:

``` python
    # check the exist_interfaces whether it equals the interfaces or not
    def check_interface_properties(self, exist_interface_list, interfaces):
        interfaces_port_list = []
        if interfaces is not None:
          if len(interfaces) >= 1:
            for interface in interfaces
```

Line "if interfaces is not None:" was added.



Discussion:

Resolving patch:
diff --git a/monitoring/zabbix_host.py b/monitoring/zabbix_host.py
--- a/monitoring/zabbix_host.py
+++ b/monitoring/zabbix_host.py
@@ -289,9 +289,11 @@ def get_host_groups_by_host_id(self, host_id):
     # check the exist_interfaces whether it equals the interfaces or not
     def check_interface_properties(self, exist_interface_list, interfaces):
         interfaces_port_list = []
-        if len(interfaces) >= 1:
-            for interface in interfaces:
-                interfaces_port_list.append(int(interface['port']))
+
+        if interfaces is not None:
+            if len(interfaces) >= 1:
+                for interface in interfaces:
+                    interfaces_port_list.append(int(interface['port']))
 
         exist_interface_ports = []
         if len(exist_interface_list) >= 1:


Test patch:
Repository: ansible/ansible-modules-extras

Issue:
firewalld: 'AnsibleModule' object has no attribute 'fail'
##### Issue Type:

Bug Report
##### Plugin Name:

firewalld
##### Ansible Version:

```
ansible 2.0.1.0
  config file = /etc/ansible/ansible.cfg
  configured module search path = Default w/o overrides
```

```
$ rpm -q ansible
ansible-2.0.1.0-2.fc23.noarch
```

Also Ansible-modules-extras from Git b51efc51bc64ef99b389acb6166d0eb46d984085 is affected.
##### Ansible Configuration:

None of `ANSIBLE_*` environment variables was used.
##### Environment:

OS running the ansible: Fedora release 23 (Twenty Three)

Target OS:
NAME="Red Hat Enterprise Linux Server"
VERSION="7.2 (Maipo)"
firewalld-0.3.9-14.el7.noarch
##### Summary:

firewalld module errors out with traceback mentioning `'AnsibleModule' object has no attribute 'fail'`
##### Steps To Reproduce:

Use following line in a playbook:

```
firewalld: zone=trusted port=162/udp state=enabled
```
##### Expected Results:

Nice error message should be shown.
##### Actual Results:

```
FAILED! => {"changed": false, "failed": true, "module_stderr": "", "module_stdout": "Traceback (most recent call last):\r\n  File \"/root/.ansible/tmp/ansible-tmp-1457431501.25-269740621439842/firewalld\", line 2415, in <module>\r\n    main()\r\n  File \"/root/.ansible/tmp/ansible-tmp-1457431501.25-269740621439842/firewalld\", line 256, in main\r\n    module.fail(msg='permanent is a required parameter')\r\nAttributeError: 'AnsibleModule' object has no attribute 'fail'\r\n", "msg": "MODULE FAILURE", "parsed": false}
```



Discussion:

Resolving patch:
diff --git a/system/firewalld.py b/system/firewalld.py
--- a/system/firewalld.py
+++ b/system/firewalld.py
@@ -260,7 +260,7 @@ def main():
         supports_check_mode=True
     )
     if module.params['source'] == None and module.params['permanent'] == None:
-        module.fail(msg='permanent is a required parameter')
+        module.fail_json(msg='permanent is a required parameter')
 
     if not HAS_FIREWALLD:
         module.fail_json(msg='firewalld and its python 2 module are required for this module')


Test patch:
Repository: ansible/ansible-modules-extras

Issue:
Blockinfile module : Documentation mistake
##### Issue Type:
- Documentation Report
##### Plugin Name:

Blockinfile module
##### Ansible Version:

```
$ ansible --version
ansible 2.0.1.0
  config file = /data/ansible/ansible.cfg
  configured module search path = Default w/o overrides
```
##### Ansible Configuration:

n.a.
##### Environment:

n.a
##### Summary:

Wrong spacing in official documentation
##### Steps To Reproduce:

```
https://docs.ansible.com/ansible/blockinfile_module.html
Chapter Example, last example using < with_items >
```
##### Expected Results:

Expression with_items: should be level with blockinfile:
##### Actual Results:

```
Example does not work as expression < with_items: > is not level with  <blockinfile:> 
```



Discussion:

Resolving patch:
diff --git a/files/blockinfile.py b/files/blockinfile.py
--- a/files/blockinfile.py
+++ b/files/blockinfile.py
@@ -144,10 +144,10 @@
     block: |
       {{item.name}} {{item.ip}}
     marker: "# {mark} ANSIBLE MANAGED BLOCK {{item.name}}"
-    with_items:
-        - { name: host1, ip: 10.10.1.10 }
-        - { name: host2, ip: 10.10.1.11 }
-        - { name: host3, ip: 10.10.1.12 }
+  with_items:
+      - { name: host1, ip: 10.10.1.10 }
+      - { name: host2, ip: 10.10.1.11 }
+      - { name: host3, ip: 10.10.1.12 }
 """
 
 


Test patch:
Repository: ansible/ansible-modules-extras

Issue:
mongodb_user ValueError: The value of ssl must be 'true' or 'false'\r\n", "msg": "MODULE FAILURE
##### Issue Type:

<!-- Please pick one and delete the rest: -->
- Bug Report
##### Plugin Name:

mongodb_user
##### Ansible Version:

```
ansible 2.1.0
```
##### Ansible Configuration:
##### Environment:

centos 7.2.1511
mongodb 3.0.6
##### Summary:

New install of mongodb no auth, connecting on localhost, cannot create mongodb users 
##### Steps To Reproduce:

<!-- For bugs, please show exactly how to reproduce the problem.
For new features, show how the feature would be used.  -->

```
- name: Mongodb | create Mongo users
  mongodb_user:
    database: admin
    name: "{{ item.name }}"
    roles: "{{ item.roles }}"
    password: "{{ MONGODB_PASSWD }}"
    state: present
  with_items:
  - { name: "siteUserAdmin", roles: "userAdminAnyDatabase" }
  - { name: "siteRootAdmin", roles: "root" }
  tags: mongo

```
##### Expected Results:

mongodb users created 
##### Actual Results:

```
failed: [10.163.49.67] (item={u'name': u'siteRootAdmin', u'roles': u'root'}) => {"failed": true, "invocation": {"module_name": "mongodb_user"}, "item": {"name": "siteRootAdmin", "roles": "root"}, "module_stderr": "", "module_stdout": "\r\nTraceback (most recent call last):\r\n  File \"/home/admin/.ansible/tmp/ansible-tmp-1458297213.91-72274712879110/mongodb_user\", line 2358, in <module>\r\n    main()\r\n  File \"/home/admin/.ansible/tmp/ansible-tmp-1458297213.91-72274712879110/mongodb_user\", line 258, in main\r\n    client = MongoClient(login_host, int(login_port), ssl=ssl)\r\n  File \"/usr/lib64/python2.7/site-packages/pymongo/mongo_client.py\", line 342, in __init__\r\n    for k, v in keyword_opts.items())\r\n  File \"/usr/lib64/python2.7/site-packages/pymongo/mongo_client.py\", line 342, in <genexpr>\r\n    for k, v in keyword_opts.items())\r\n  File \"/usr/lib64/python2.7/site-packages/pymongo/common.py\", line 471, in validate\r\n    value = validator(option, value)\r\n  File \"/usr/lib64/python2.7/site-packages/pymongo/common.py\", line 131, in validate_boolean_or_string\r\n    \"'true' or 'false'\" % (option,))\r\nValueError: The value of ssl must be 'true' or 'false'\r\n", "msg": "MODULE FAILURE", "parsed": false}

```



Discussion:
I wonder if that's not because ssl is not tagged as boolean in the module. I will test it once I manage to get mongo running.

Could be related to #1732 


Resolving patch:
diff --git a/database/misc/mongodb_user.py b/database/misc/mongodb_user.py
--- a/database/misc/mongodb_user.py
+++ b/database/misc/mongodb_user.py
@@ -225,7 +225,7 @@ def main():
             database=dict(required=True, aliases=['db']),
             name=dict(required=True, aliases=['user']),
             password=dict(aliases=['pass']),
-            ssl=dict(default=False),
+            ssl=dict(default=False, type='bool'),
             roles=dict(default=None, type='list'),
             state=dict(default='present', choices=['absent', 'present']),
             update_password=dict(default="always", choices=["always", "on_create"]),


Test patch:
Repository: ansible/ansible-modules-extras

Issue:
osx_defaults fails with type set to string: "TypeError: isinstance() arg 2 must be a class, type, or tuple of classes and types"
##### Issue Type:
- Bug
##### Plugin Name:

osx_defaults
##### Ansible Version:

```
ansible 2.0.1.0
  config file = /Users/danbohea/mac-playbook/ansible.cfg
  configured module search path = Default w/o overrides
```
##### Ansible Configuration:

```
[defaults]
gathering = smart
hostfile = ./hosts
log_path = ./ansible.log
roles_path = ext_roles
```
##### Environment:

Reproduced in:
- Mac OS 10.9
- Mac OS 10.11

(10.10 wasn't available to test in)
##### Summary:

Ansible fails when using `type` property `string` with the osx_defaults module.
##### Steps To Reproduce:

```
# This equivalent `defaults` command would work:
# defaults write NSGlobalDomain AppleShowScrollBars -string "Always"
- name: Always show scrollbars
  osx_defaults:
    domain: NSGlobalDomain
    key: AppleShowScrollBars
    type: string
    value: "Always"
```
##### Expected Results:

I'd expect the task to report with "OK" or "Changed" depending on the system state at the time.
##### Actual Results:

```
An exception occurred during task execution. To see the full traceback, use -vvv. The error was: TypeError: isinstance() arg 2 must be a class, type, or tuple of classes and types
fatal: [mba]: FAILED! => {"changed": false, "failed": true, "parsed": false}
```



Discussion:

Resolving patch:
diff --git a/system/osx_defaults.py b/system/osx_defaults.py
--- a/system/osx_defaults.py
+++ b/system/osx_defaults.py
@@ -83,7 +83,7 @@
 - osx_defaults: domain=com.geekchimp.macable key=ExampleKeyToRemove state=absent
 '''
 
-from datetime import datetime
+import datetime
 
 # exceptions --------------------------------------------------------------- {{{
 class OSXDefaultsException(Exception):
@@ -141,7 +141,7 @@ def _convert_type(self, type, value):
             raise OSXDefaultsException("Invalid boolean value: {0}".format(repr(value)))
         elif type == "date":
             try:
-                return datetime.strptime(value.split("+")[0].strip(), "%Y-%m-%d %H:%M:%S")
+                return datetime.datetime.strptime(value.split("+")[0].strip(), "%Y-%m-%d %H:%M:%S")
             except ValueError:
                 raise OSXDefaultsException(
                     "Invalid date value: {0}. Required format yyy-mm-dd hh:mm:ss.".format(repr(value))
@@ -240,7 +240,7 @@ def write(self):
             value = str(self.value)
         elif self.array_add and self.current_value is not None:
             value = list(set(self.value) - set(self.current_value))
-        elif isinstance(self.value, datetime):
+        elif isinstance(self.value, datetime.datetime):
             value = self.value.strftime('%Y-%m-%d %H:%M:%S')
         else:
             value = self.value


Test patch:
Repository: ansible/ansible-modules-extras

Issue:
module promox is broken with Proxmox VE 4.0
AFAIK proxmox dropped support of openvz container in favor of lxc in the latest release (4.0 as of today), but module proxmox uses the openvz type container.
Any attempt for me gave an error 501, confirmed by the pveproxy log `"POST /api2/json/nodes/cactus/openvz HTTP/1.1" 501 130"`

I tried to replace any `openvz` call by a `lxc` call but it doesn't suffice to make the module work.
it returns such error

``` bash
failed: [localhost] => {"failed": true}
msg: creation of VM 102 failed with exception: 400 Bad Request
```

it is confirmed by the entry I got in the pveproxy log



Discussion:
I'm still stuck trying to debug what the server does expect but I cannot find information.
I'd appreciate any advise to get more information on server or client side.

Thansk

@bmillemathias -- thanks for filing this bug report.

@undergreen -- thanks in advance for taking a look at this bug report and for your ongoing work in maintaining this module.

[module: cloud/misc/proxmox.py]

The openvz to lxc migration patch is located at https://github.com/bmillemathias/ansible-modules-extras/commit/2ee4bc08c910d866bf8d8f862bd84e61ef6da3a8

http://pve.proxmox.com/wiki/Manual:_pct look at the create command for the changed things, it should be do-able to adapt this for PVE4, using if clauses do differ between PVE2/3 and PVE4 should suffice to not break compatibility.
I haven't done anything with ansible, but will try to give it a look, but no promises :)

Hi there.
Has someone started to look at this a bit further?


Resolving patch:
diff --git a/cloud/misc/proxmox.py b/cloud/misc/proxmox.py
--- a/cloud/misc/proxmox.py
+++ b/cloud/misc/proxmox.py
@@ -213,6 +213,9 @@ def create_instance(module, proxmox, vmid, node, disk, storage, cpus, memory, sw
   if VZ_TYPE =='lxc':
       kwargs['cpulimit']=cpus
       kwargs['rootfs']=disk
+      if 'netif' in kwargs:
+        kwargs.update(kwargs['netif'])
+        del kwargs['netif']
   else:
       kwargs['cpus']=cpus
       kwargs['disk']=disk


Test patch:
Repository: ansible/ansible-modules-extras

Issue:
Expect module silently kills tasks after timeout is exceeded even if all questions were answered
##### ISSUE TYPE
- Bug Report
##### ANSIBLE VERSION

```
2.1.0
```
##### OS / ENVIRONMENT

N/A
##### SUMMARY

It turns out that tasks fail after default (30s) timeout is reached even if all the questions 
were already handled by "expect" module.
##### STEPS TO REPRODUCE
1. run a task that requires "answers"
2. the task should run longer than default timeout
3. task if marked as failed without any apparent reason

this fails for me after a while:

```
- name: install App
  become_user: foo
  expect:
    command: foo bar baz
    responses:
      (?i)license: y
```

this works properly till the end:

```
- name: install App
  become_user: foo
  expect:
    command: foo bar baz
    responses:
      (?i)license: y
    timeout: 600
```

Example error

```
fatal: [172.16.115.209]: FAILED! => {"changed": true, "cmd": "/home/rcdev/.rccontrol-profile/bin/rccontrol install VCSServer host:127.0.0.1 port:10001", "delta": "0:00:30.589820", "end": "2016-06-27 15:33:23.161709", "failed": true, "invocation": {"module_args": {"chdir": null, "command": "/home/rc...", "creates": null, "echo": false, "removes": null, "responses": {"(?i)license": "y"}, "timeout": 30}, "module_name": "expect"}, "rc": null, "start": "2016-06-27 15:32:52.571889", "stdout": "Do you accept the REDACTED \r\nDownloading ....tar.bz2 ...", "stdout_lines": ["Do you accept ..."]}
```



Discussion:

Resolving patch:
diff --git a/commands/expect.py b/commands/expect.py
--- a/commands/expect.py
+++ b/commands/expect.py
@@ -214,7 +214,7 @@ def main():
     if out is None:
         out = ''
 
-    module.exit_json(
+    ret = dict(
         cmd=args,
         stdout=out.rstrip('\r\n'),
         rc=rc,
@@ -224,6 +224,12 @@ def main():
         changed=True,
     )
 
+    if rc:
+        module.exit_json(**ret)
+    else:
+        ret['msg'] = 'command exceeded timeout'
+        module.fail_json(**ret)
+
 # import module snippets
 from ansible.module_utils.basic import *
 


Test patch:
Repository: ansible/ansible-modules-extras

Issue:
modprobe: Call 'modprobe -r' instasd of 'rmmod' for absent?
##### ISSUE TYPE
- Feature Idea
##### COMPONENT NAME

modprobe
##### ANSIBLE VERSION

```
ansible 2.0.1.0
  config file =
  configured module search path = Default w/o overrides
```
##### CONFIGURATION

N/A
##### OS / ENVIRONMENT

N/A (linux target)
##### SUMMARY

Current implementation of modprobe module uses `rmmod` command to remove kernel module.
https://github.com/ansible/ansible-modules-extras/blob/stable-2.1/system/modprobe.py#L114

Why don't we use `modprobe -r` instead of `rmmod` here?

`modprobe -r` would be better because; 
1. It will also unload unused modules
2. Straight forward from module name
##### STEPS TO REPRODUCE

I was trying to unload sb_edac module from my server (since it conflict with some hardware monitoring of server), the module depends on edac_core and edac_core was loaded only for sb_edac.

Before applying playbook, on the target server.

```
server# lsmod | grep edac
sb_edac                28672  0
edac_core              53248  1 sb_edac
```

playbook (snippet)

```
- name: unload edac modules
  modprobe:
    name: sb_edac
    state: absent
```
##### EXPECTED RESULTS

edac_core module unloaded, since it no longer be used.
##### ACTUAL RESULTS

After applying playbook, on the target server.

```
server# lsmod | grep edac
edac_core              53248  0
```



Discussion:
<!-- @haeena: Thanks for filing this feature idea! -->

@stygstra ping, this issue is waiting for your response.
[click here for bot help](https://github.com/ansible/ansibullbot/blob/master/ISSUE_HELP.md)

<!--- boilerplate: issue_bug_new --->


Resolving patch:
diff --git a/system/modprobe.py b/system/modprobe.py
--- a/system/modprobe.py
+++ b/system/modprobe.py
@@ -114,7 +114,7 @@ def main():
             args['changed'] = True
     elif args['state'] == 'absent':
         if present:
-            rc, _, err = module.run_command([module.get_bin_path('rmmod', True), args['name']])
+            rc, _, err = module.run_command([module.get_bin_path('modprobe', True), '-r', args['name']])
             if rc != 0:
                 module.fail_json(msg=err, **args)
             args['changed'] = True


Test patch:
Repository: ansible/ansible-modules-extras

Issue:
rabbitmq_binding can't set empty routing_key
<!--- Verify first that your issue/request is not already reported in GitHub -->
##### ISSUE TYPE

<!--- Pick one below and delete the rest: -->
- Bug Report
##### COMPONENT NAME

<!--- Name of the plugin/module/task -->

messaging/rabbitmq_binding
##### ANSIBLE VERSION

```
ansible 2.0.1.0
  config file = /etc/ansible/ansible.cfg
  configured module search path = Default w/o overrides
```
##### 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.
-->

N/A
##### SUMMARY

<!--- Explain the problem briefly -->

Module set routing_key="#" by default, so rabbitmq can't work when routing_key isn't set in messages. I'm tried to set routing_key='' in task, but ansible just mark it as OK and doesn't add binding.
##### STEPS TO REPRODUCE

```
-  rabbitmq_binding: name=mailer destination=mailer type=queue
```

<!--- You can also paste gist.github.com links for larger files -->
##### EXPECTED RESULTS

<!--- What did you expect to happen when running the steps above? -->

```
$ rabbitmqctl list_bindings
Listing bindings ...
  exchange  mailer  queue  mailer  []
mailer  exchange  mailer  queue    []
$
```
##### ACTUAL RESULTS

<!--- What actually happened? If possible run with high verbosity (-vvvv) -->

```
$ rabbitmqctl list_bindings
Listing bindings ...
  exchange  mailer  queue  mailer  []
mailer  exchange  mailer  queue  #  []
$
```

<!--- Paste verbatim command output between quotes -->

```
TASK [RabbitMQ : add rabbitmq bindings] ****************************************
ok: [%host_ip%] => (item={u'source': u'mailer', u'destination': u'mailer', u'destination_type': u'queue'})
```



Discussion:
<!-- @unclegaara: Thanks for filing this bug report! -->

@manuel-sousa ping, this issue is waiting for your response.
[click here for bot help](https://github.com/ansible/ansibullbot/blob/master/ISSUE_HELP.md)

<!--- boilerplate: issue_bug_new --->


Resolving patch:
diff --git a/messaging/rabbitmq_binding.py b/messaging/rabbitmq_binding.py
--- a/messaging/rabbitmq_binding.py
+++ b/messaging/rabbitmq_binding.py
@@ -127,6 +127,11 @@ def main():
     else:
         dest_type="e"
 
+    if module.params['routing_key'] == "":
+        props = "~"
+    else:
+        props = urllib.quote(module.params['routing_key'],'')
+
     url = "http://%s:%s/api/bindings/%s/e/%s/%s/%s/%s" % (
         module.params['login_host'],
         module.params['login_port'],
@@ -134,7 +139,7 @@ def main():
         urllib.quote(module.params['name'],''),
         dest_type,
         urllib.quote(module.params['destination'],''),
-        urllib.quote(module.params['routing_key'],'')
+        props
     )
 
     # Check if exchange already exists


Test patch:
Repository: ansible/ansible-modules-extras

Issue:
ufw fails asking for a direction for rules without an interface specified
##### ISSUE TYPE
- Bug Report
##### COMPONENT NAME

ufw
##### ANSIBLE VERSION

```
ansible 2.1.1.0 (stable-2.1 9478e41394) last updated 2016/08/18 16:06:20 (GMT -400)
  lib/ansible/modules/core: (detached HEAD 493ead2d42) last updated 2016/08/18 16:06:54 (GMT -400)
  lib/ansible/modules/extras: (detached HEAD 5a84de640b) last updated 2016/08/18 16:06:54 (GMT -400)
  config file = 
  configured module search path = Default w/o overrides
```
##### CONFIGURATION

N/A
##### OS / ENVIRONMENT

N/A
##### SUMMARY

ufw module fails asking for a direction even when rules do not include an interface parameter. The following arguments are from the [module's Examples section](http://docs.ansible.com/ansible/ufw_module.html#examples) of the documentation.
##### STEPS TO REPRODUCE

```
ansible localhost -m ufw -a "rule=allow port=80 proto=tcp"
```
##### EXPECTED RESULTS

ufw rule allowing port 80/tcp
##### ACTUAL RESULTS

```
localhost | FAILED! => {
    "changed": false, 
    "failed": true, 
    "msg": "Direction must be specified when creating a rule on an interface"
}
```



Discussion:
<!-- @mboulet: Thanks for filing this bug report! -->

@ovcharenko, @pyykkis, ping. This issue is waiting on your response.
[click here for bot help](https://github.com/ansible/ansibullbot/blob/master/ISSUE_HELP.md)

<!--- boilerplate: issue_bug_new --->

notabug Couldn't repeat in latest Ansible `ansible 2.1.1.0`. Got a changed result as expected:

```
localhost | SUCCESS => {
    "changed": true,
    "commands": [
        "/usr/sbin/ufw allow from any to any port 80 proto tcp"
    ],
...
```

@ovcharenko Respectfully, I am still experiencing this result.

[ufw.py line 228](https://github.com/ansible/ansible-modules-extras/blob/5a84de640b2773152f14b34a9f31573ef8a72541/system/ufw.py#L228) fails the modules when 'interface' is in module.params and 'direction' is None. However, [AnsibleModule._set_defaults(pre=False)](https://github.com/ansible/ansible/blob/9478e4139475adf77c0ab279fec756415e7ab24a/lib/ansible/module_utils/basic.py#L689) sets 'interface' to None by default. 'interface' is always in module.params when I run ufw.py. 


Resolving patch:
diff --git a/system/ufw.py b/system/ufw.py
--- a/system/ufw.py
+++ b/system/ufw.py
@@ -228,7 +228,7 @@ def execute(cmd):
     if len(commands) < 1:
         module.fail_json(msg="Not any of the command arguments %s given" % commands)
 
-    if('interface' in params and params['direction'] is None):
+    if(params['interface'] is not None and params['direction'] is None):
       module.fail_json(msg="Direction must be specified when creating a rule on an interface")
 
     # Ensure ufw is available


Test patch: