Initial Commit.

This commit is contained in:
James Martin 2013-05-23 13:33:36 -04:00
parent 14aa54172c
commit 3c131dbd2b
2 changed files with 28 additions and 3 deletions

View file

@ -46,12 +46,24 @@ class ActionModule(object):
options.update(utils.parse_kv(module_args))
source = options.get('src', None)
dest = options.get('dest', None)
flat = options.get('flat', False)
flat = utils.boolean(flat)
fail_on_missing = options.get('fail_on_missing', False)
fail_on_missing = utils.boolean(fail_on_missing)
if source is None or dest is None:
results = dict(failed=True, msg="src and dest are required")
return ReturnData(conn=conn, result=results)
if flat:
if dest.endswith("/"):
# if the path ends with "/", we'll use the source filename as the
# destination filename
base = os.path.basename(source)
dest = os.path.join(dest, base)
if not dest.startswith("/"):
# if dest does not start with "/", we'll assume a relative path
dest = utils.path_dwim(self.runner.basedir, dest)
else:
# files are saved in dest dir, with a subdir for each host, then the filename
dest = "%s/%s/%s" % (utils.path_dwim(self.runner.basedir, dest), conn.host, source)
dest = dest.replace("//","/")

View file

@ -34,9 +34,22 @@ options:
required: false
choices: [ "yes", "no" ]
default: "no"
flat:
version_added: "1.2"
description:
Allows you to override the default behavior of prepending hostname/path/to/file to
the destination. If dest ends with '/', it will use the basename of the source
file, similar to the copy module. Obvioiusly this is only handy if the filenames
are unqiue.
examples:
- code: "fetch: src=/var/log/messages dest=/home/logtree"
description: "Example from Ansible Playbooks"
- code: "fetch: src=/tmp/somefile dest="/tmp/beefcake-{{ ansible_hostname }}" flat=yes"
description: "Copies a file from remote machine and stores it at the absolute path /tmp/beefcake-{{ ansible_hostname }}"
- code: "fetch: src=/tmp/uniquefile dest="/tmp/special/" flat=yes"
description: "Copies a file from remote machine and stores it at the absolute path /tmp/special"
- code: "fetch: src=/tmp/uniquefile dest="special/" flat=yes"
description: "Copies a file from remote machine and stores it in special/uniquefile relative to the playbook"
requirements: []
author: Michael DeHaan
'''