Repository: ansible/ansible

Issue:
filesystem@devel: The file [/dev/xvdf] does not exist and no size was specified.
That is most likely related to #20551 

##### ISSUE TYPE
<!--- Pick one below and delete the rest: -->
 - Bug Report

##### COMPONENT NAME
filesystem

##### ANSIBLE VERSION
<!--- Paste verbatim output from “ansible --version” between quotes below -->
```
ansible 2.3.0
  config file = 
  configured module search path = Default w/o overrides

```

##### CONFIGURATION
Default

##### OS / ENVIRONMENT
<!---
N/A
-->

##### SUMMARY
filesystem module fails on CoreOS with:
```
mke2fs 1.42.13 (17-May-2015)\nThe file [/dev/xvdf] does not exist and no size was specified.\n
```

##### STEPS TO REPRODUCE

```yaml
- filesystem: fstype=ext4 dev=/dev/xvdf force=yes
```

##### EXPECTED RESULTS
Filesystem is created on a given block device.

##### ACTUAL RESULTS
Error is thrown.

<!--- Paste verbatim command output between quotes below -->
```
fatal: [35.157.42.174]: FAILED! => {
    "changed": false, 
    "err": "mke2fs 1.42.13 (17-May-2015)\nThe file [/dev/xvdf] does not exist and no size was specified.\n", 
    "failed": true, 
    "invocation": {
        "module_args": {
            "dev": [
                "/dev/xvdf"
            ], 
            "force": true, 
            "fstype": "ext4", 
            "opts": null, 
            "resizefs": false
        }
    }, 
    "msg": "Creating filesystem ext4 on device '['/dev/xvdf']' failed", 
    "rc": 1
}
```



Discussion:
cc @abulimov
[click here for bot help](https://github.com/ansible/ansibullbot/blob/master/ISSUE_HELP.md)
<!--- boilerplate: notify --->
yep,  see that as well.

Since now dev is a list, the command used fail, since that's not list aware.
```
    "cmd": "/usr/sbin/pvcreate --force '['/dev/vdb']'", 
```


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


Test patch: