Repository: ansible/ansible

Issue:
filesystem does not support multiple devices (on btrfs f.e.) #3338
Moved from: https://github.com/ansible/ansible-modules-extras/issues/3338

##### ISSUE TYPE
- Feature Idea
 - ~~Bug Report~~

##### COMPONENT NAME
`filesystem` module

##### ANSIBLE VERSION
```
ansible 2.1.2.0
  config file = /home/pasha/Projects/Ansible.cfg/ansible.cfg
  configured module search path = ['modules/']
```

##### CONFIGURATION
Does not have sence

##### OS / ENVIRONMENT
Fedora repos

##### SUMMARY

Task:
```
- name: Create btrfs filesystem
  filesystem: fstype=btrfs dev='/dev/mapper/centos-home' opts='--label srv'
```
work as expected, but:
```
- name: Create btrfs filesystem
  filesystem: fstype=btrfs dev='/dev/sda3 /dev/sdb' opts='-d single --label srv'
```
Produce error: 
```
**Device /dev/sda3 /dev/sdb not found.**
```

##### EXPECTED RESULTS
`Btrfs` (and some other like `zfs` too) allow create filesystems across multiple devices - https://btrfs.wiki.kernel.org/index.php/Using_Btrfs_with_Multiple_Devices

So, it seams reasonable make `dev` parameter the list type or just allow pass any string.



Discussion:
cc @abulimov
[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/filesystem.py b/lib/ansible/modules/system/filesystem.py
--- a/lib/ansible/modules/system/filesystem.py
+++ b/lib/ansible/modules/system/filesystem.py
@@ -38,7 +38,7 @@
     required: true
   dev:
     description:
-    - Target block device.
+    - Target block device. Starting in 2.3 it can also take a list of devices for file systems that allow this.
     required: true
   force:
     choices: [ "yes", "no" ]
@@ -73,6 +73,9 @@
     opts: -cc
 '''
 
+import os
+from ansible.module_utils.basic import AnsibleModule
+
 def _get_dev_size(dev, module):
     """ Return size in bytes of device. Returns int """
     blockdev_cmd = module.get_bin_path("blockdev", required=True)
@@ -121,7 +124,7 @@ def main():
     module = AnsibleModule(
         argument_spec = dict(
             fstype=dict(required=True, aliases=['type']),
-            dev=dict(required=True, aliases=['device']),
+            dev=dict(required=True, aliases=['device'], type='list'),
             opts=dict(),
             force=dict(type='bool', default='no'),
             resizefs=dict(type='bool', default='no'),
@@ -200,12 +203,13 @@ def main():
     growcmd = fs_cmd_map[fstype]['grow']
     fssize_cmd = fs_cmd_map[fstype]['fsinfo']
 
-    if not os.path.exists(dev):
-        module.fail_json(msg="Device %s not found."%dev)
+    for device in dev:
+        if not os.path.exists(device):
+            module.fail_json(msg="Device %s not found." % device)
 
     cmd = module.get_bin_path('blkid', required=True)
 
-    rc,raw_fs,err = module.run_command("%s -c /dev/null -o value -s TYPE %s" % (cmd, dev))
+    rc,raw_fs,err = module.run_command("%s -c /dev/null -o value -s TYPE %s" % (cmd, ' '.join(dev)))
     fs = raw_fs.strip()
 
     if fs == fstype and resizefs == False and not force:
@@ -259,7 +263,5 @@ def main():
 
     module.exit_json(changed=changed)
 
-# import module snippets
-from ansible.module_utils.basic import *
 if __name__ == '__main__':
     main()


Test patch: