From bcc058249cf01529db6611a402584907c889317b Mon Sep 17 00:00:00 2001 From: Toshio Kuratomi Date: Mon, 20 Oct 2014 22:25:18 -0400 Subject: [PATCH] Use original_basename to set the dest path even if src is not set --- lib/ansible/modules/files/file.py | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/lib/ansible/modules/files/file.py b/lib/ansible/modules/files/file.py index ff9feb41ee3..be7b05aaf52 100644 --- a/lib/ansible/modules/files/file.py +++ b/lib/ansible/modules/files/file.py @@ -168,14 +168,6 @@ def main(): # or copy module, even if this module never uses it, it is needed to key off some things if src is not None: src = os.path.expanduser(src) - - # original_basename is used by other modules that depend on file. - if os.path.isdir(path) and state not in ["link", "absent"]: - if params['original_basename']: - basename = params['original_basename'] - else: - basename = os.path.basename(src) - params['path'] = path = os.path.join(path, basename) else: if state in ['link','hard']: if follow: @@ -184,6 +176,16 @@ def main(): else: module.fail_json(msg='src and dest are required for creating links') + # original_basename is used by other modules that depend on file. + if os.path.isdir(path) and state not in ["link", "absent"]: + basename = None + if params['original_basename']: + basename = params['original_basename'] + elif src is not None: + basename = os.path.basename(src) + if basename: + params['path'] = path = os.path.join(path, basename) + # make sure the target path is a directory when we're doing a recursive operation recurse = params['recurse'] if recurse and state != 'directory':