From 0037a193896c139520f6839702a3972c5a6ee2d0 Mon Sep 17 00:00:00 2001 From: Michel Blanc Date: Thu, 3 Jan 2013 15:57:14 +0100 Subject: [PATCH 1/2] Expands path on file operations Path might have to be expanded on some operations. It seems that path containing '~' are not. Using os.path.expanduser in appropriate places solves the problem, but this might be required in many other places. --- lib/ansible/module_common.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/ansible/module_common.py b/lib/ansible/module_common.py index 51fb1f7499a..5d840bb60f7 100644 --- a/lib/ansible/module_common.py +++ b/lib/ansible/module_common.py @@ -262,6 +262,7 @@ class AnsibleModule(object): return context def user_and_group(self, filename): + filename = os.path.expanduser(filename) st = os.stat(filename) uid = st.st_uid gid = st.st_gid @@ -338,6 +339,8 @@ class AnsibleModule(object): return changed def set_mode_if_different(self, path, mode, changed): + path = os.path.expanduser(path) + if mode is None: return changed try: From 7d7e7fb8bc00f954b9f8e7bfccf2c914a05de650 Mon Sep 17 00:00:00 2001 From: Michel Blanc Date: Fri, 4 Jan 2013 13:41:31 +0100 Subject: [PATCH 2/2] Adds path expansion to two other methods set_owner_if_different and set_group_if_different seems to need path expansion too --- lib/ansible/module_common.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/ansible/module_common.py b/lib/ansible/module_common.py index 5d840bb60f7..f126f12f280 100644 --- a/lib/ansible/module_common.py +++ b/lib/ansible/module_common.py @@ -307,6 +307,7 @@ class AnsibleModule(object): return changed def set_owner_if_different(self, path, owner, changed): + path = os.path.expanduser(path) if owner is None: return changed user, group = self.user_and_group(path) @@ -323,6 +324,7 @@ class AnsibleModule(object): return changed def set_group_if_different(self, path, group, changed): + path = os.path.expanduser(path) if group is None: return changed old_user, old_group = self.user_and_group(path) @@ -340,7 +342,6 @@ class AnsibleModule(object): def set_mode_if_different(self, path, mode, changed): path = os.path.expanduser(path) - if mode is None: return changed try: