Repository: ansible/ansible-modules-core

Issue:
Mount module does not accept spaces in mount point path
##### Issue Type:

Bug Report
##### Ansible Version:

ansible 1.9 (devel 27d2539fcd) last updated 2014/12/16 17:34:16 (GMT +200)
  lib/ansible/modules/core: (detached HEAD 08c5cc06c6) last updated 2014/12/16 17:34:20 (GMT +200)
  lib/ansible/modules/extras: (detached HEAD 317654dba5) last updated 2014/12/16 17:34:24 (GMT +200)
  v2/ansible/modules/core: (detached HEAD cb69744bce) last updated 2014/12/16 17:34:30 (GMT +200)
  v2/ansible/modules/extras: (detached HEAD 8a4f07eecd) last updated 2014/12/16 17:34:34 (GMT +200)
  configured module search path = None
##### Environment:

Control host and remote host both Ubuntu 14.04
##### Summary:

I'm trying to have a volume mounted inside VMare Workstation Server's sharde vm path, which contains spaces : `/var/lib/vmware/Shared VMs/`
##### Steps To Reproduce:

The offending task is: 

```
- name: Le système de fichiers doit être monté dans le dossier VMWare
  mount: name="/var/lib/vmware/Shared VMs/{{ inventory_hostname }}"
         src=/dev/drbd/by-res/{{ inventory_hostname }}
         passno=2
         fstype=ext4
         state=mounted
         opts=noauto
  delegate_to: "{{ master }}"
```
##### Expected Results:

Ansible should accept spaces and take the necessary steps to escape them in the updated fstab.
The usual way to represent spaces in paths in fstab is to replace them with `\040`.
##### Actual Results:

```
<vmhost9> ESTABLISH CONNECTION FOR USER: root
<vmhost9> REMOTE_MODULE mount name="/var/lib/vmware/Shared VMs/vmls" src=/dev/drbd/by-res/vmls passno=2 fstype=ext4 state=mounted opts=noauto
<vmhost9> EXEC ssh -C -vvv -o ControlMaster=auto -o ControlPersist=60s -o ForwardAgent=yes -o ControlPath="/home/ls/.ansible/cp/ansible-ssh-%h-%p-%r" -o Port=22 -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o User=root -o ConnectTimeout=10 vmhost9 /bin/sh -c 'LANG=fr LC_CTYPE=fr /usr/bin/python'
failed: [vmls -> vmhost9] => {"failed": true}
msg: Error mounting /var/lib/vmware/Shared VMs/vmls: [mntent]: line 13 in /etc/fstab is bad
mount: can't find /var/lib/vmware/Shared VMs/vmls in /etc/fstab or /etc/mtab
```

Contents of fstab on delegate host:

```
/dev/drbd/by-res/vmls /var/lib/vmware/Shared VMs/vmls ext4 noauto 0 2
```



Discussion:

Resolving patch:
diff --git a/system/mount.py b/system/mount.py
--- a/system/mount.py
+++ b/system/mount.py
@@ -114,6 +114,11 @@ def set_mount(**kwargs):
     )
     args.update(kwargs)
 
+    # save the mount name before space replacement
+    origname =  args['name']
+    # replace any space in mount name with '\040' to make it fstab compatible (man fstab)
+    args['name'] = args['name'].replace(' ', r'\040')
+
     new_line = '%(src)s %(name)s %(fstype)s %(opts)s %(dump)s %(passno)s\n'
 
     to_write = []
@@ -158,7 +163,8 @@ def set_mount(**kwargs):
     if changed:
         write_fstab(to_write, args['fstab'])
 
-    return (args['name'], changed)
+    # mount function needs origname
+    return (origname, changed)
 
 
 def unset_mount(**kwargs):
@@ -173,6 +179,11 @@ def unset_mount(**kwargs):
     )
     args.update(kwargs)
 
+    # save the mount name before space replacement
+    origname =  args['name']
+    # replace any space in mount name with '\040' to make it fstab compatible (man fstab)
+    args['name'] = args['name'].replace(' ', r'\040')
+
     to_write = []
     changed = False
     for line in open(args['fstab'], 'r').readlines():
@@ -201,7 +212,8 @@ def unset_mount(**kwargs):
     if changed:
         write_fstab(to_write, args['fstab'])
 
-    return (args['name'], changed)
+    # umount needs origname
+    return (origname, changed)
 
 
 def mount(module, **kwargs):


Test patch: