From 4e50478a05b220792023d5b43a14bb6de52958ee Mon Sep 17 00:00:00 2001 From: willthames Date: Mon, 7 Jan 2013 16:30:29 +1000 Subject: [PATCH] Fix behaviour when file handles a path with tilde Two problems here * unchecked exception handling and erroneous assumption as to why an exception might fire * although the file module expands the path, when using file_args the unexpanded path is passed. Expected result: ~/path/to/file should work fine Actual result: exception is because it doesn't find file with a message about not being able to get the selinux context --- lib/ansible/module_common.py | 7 +++++-- library/file | 2 +- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/lib/ansible/module_common.py b/lib/ansible/module_common.py index d6ed081faed..f56dc96f430 100644 --- a/lib/ansible/module_common.py +++ b/lib/ansible/module_common.py @@ -254,8 +254,11 @@ class AnsibleModule(object): return context try: ret = selinux.lgetfilecon(path) - except: - self.fail_json(path=path, msg='failed to retrieve selinux context') + except OSError, e: + if e.errno == errno.ENOENT: + self.fail_json(path=path, msg='path %s does not exist' % path) + else: + self.fail_json(path=path, msg='failed to retrieve selinux context') if ret[0] == -1: return context context = ret[1].split(':') diff --git a/library/file b/library/file index ff51608c231..4678edd6658 100644 --- a/library/file +++ b/library/file @@ -139,7 +139,7 @@ def main(): params = module.params state = params['state'] - path = os.path.expanduser(params['path']) + params['path'] = path = os.path.expanduser(params['path']) # source is both the source of a symlink or an informational passing of the src for a template module # or copy module, even if this module never uses it, it is needed to key off some things