Repository: ansible/ansible

Issue:
Seport: support list input for ports
<!---
Verify first that your issue/request is not already reported on GitHub.
Also test if the latest release, and devel branch are affected too.
-->

##### ISSUE TYPE
<!--- Pick one below and delete the rest -->
 - Feature Idea

##### COMPONENT NAME
<!---
Name of the module, plugin, task or feature
Do not include extra details here, e.g. "vyos_command" not "the network module vyos_command" or the full path
-->
seport

##### ANSIBLE VERSION
<!--- Paste verbatim output from "ansible --version" between quotes below -->
```
ansible 2.4.3.0
```

##### 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).
-->

##### 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 -->
It would be nice if the `ports` option allowed for a list of strings instead of just a string.

https://github.com/ansible/ansible/blob/devel/lib/ansible/modules/system/seport.py#L234

##### 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 -->
##### EXPECTED RESULTS
```yaml
- seport:
    ports: 
    - "10000-10100"
    - "10112"
    proto: tcp
    setype: memcache_port_t
    state: present
```

##### ACTUAL RESULTS
```yaml
- seport:
    ports: 10000-10100,10112
    proto: tcp
    setype: memcache_port_t
    state: present
```



Discussion:
Files identified in the description:
* [lib/ansible/modules/system/seport.py](https://github.com/ansible/ansible/blob/devel/lib/ansible/modules/system/seport.py)

If these files are inaccurate, please update the `component name` section of the description or use the `!component` bot command.

[click here for bot help](https://github.com/ansible/ansibullbot/blob/master/ISSUE_HELP.md)
<!--- boilerplate: components_banner --->
cc @dankeder
[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/seport.py b/lib/ansible/modules/system/seport.py
--- a/lib/ansible/modules/system/seport.py
+++ b/lib/ansible/modules/system/seport.py
@@ -15,12 +15,12 @@
 module: seport
 short_description: Manages SELinux network port type definitions
 description:
-     - Manages SELinux network port type definitions.
+    - Manages SELinux network port type definitions.
 version_added: "2.0"
 options:
   ports:
     description:
-      - Ports or port ranges, separated by a comma.
+      - Ports or port ranges. Can be a list (since 2.6) or comma separated string.
     required: true
   proto:
     description:
@@ -73,6 +73,15 @@
     proto: tcp
     setype: memcache_port_t
     state: present
+
+- name: Allow memcached to listen on tcp ports 10000-10100 and 10112
+  seport:
+    ports:
+      - 10000-10100
+      - 10112
+    proto: tcp
+    setype: memcache_port_t
+    state: present
 '''
 
 import traceback
@@ -231,7 +240,7 @@ def semanage_port_del(module, ports, proto, setype, do_reload, sestore=''):
 def main():
     module = AnsibleModule(
         argument_spec=dict(
-            ports=dict(type='str', required=True),
+            ports=dict(type='list', required=True),
             proto=dict(type='str', required=True, choices=['tcp', 'udp']),
             setype=dict(type='str', required=True),
             state=dict(type='str', required=True, choices=['absent', 'present']),
@@ -249,7 +258,7 @@ def main():
     if not selinux.is_selinux_enabled():
         module.fail_json(msg="SELinux is disabled on this host.")
 
-    ports = [x.strip() for x in str(module.params['ports']).split(',')]
+    ports = module.params['ports']
     proto = module.params['proto']
     setype = module.params['setype']
     state = module.params['state']


Test patch: