From 3b2d409906f794c3e2b197bbd1423b07b01ca97e Mon Sep 17 00:00:00 2001 From: James Cammarata Date: Mon, 24 Feb 2014 14:24:25 -0600 Subject: [PATCH] Fixing several bugs in assemble and updating tests Bugfixes: * the remote_src param was not being converted to a boolean correctly, resulting in it never being used by the module as the default behavior was remote_src=True (issue #5581) * the remote_src param was not listed in the generic file params, leading to a failure when the above bug regarding remote_src was fixed * the delimiter should always end with a newline to ensure that the file fragments do not run together on one line Fixes #5581 --- lib/ansible/module_utils/basic.py | 1 + lib/ansible/runner/action_plugins/assemble.py | 4 +++- library/files/assemble | 6 +++++- tests_new/integration/roles/test_assemble/tasks/main.yml | 2 +- 4 files changed, 10 insertions(+), 3 deletions(-) diff --git a/lib/ansible/module_utils/basic.py b/lib/ansible/module_utils/basic.py index 3be407fe707..c2be621d4bf 100644 --- a/lib/ansible/module_utils/basic.py +++ b/lib/ansible/module_utils/basic.py @@ -111,6 +111,7 @@ FILE_COMMON_ARGUMENTS=dict( content = dict(), backup = dict(), force = dict(), + remote_src = dict(), # used by assemble ) def get_platform(): diff --git a/lib/ansible/runner/action_plugins/assemble.py b/lib/ansible/runner/action_plugins/assemble.py index 773f77e6b19..cc4c4bd1564 100644 --- a/lib/ansible/runner/action_plugins/assemble.py +++ b/lib/ansible/runner/action_plugins/assemble.py @@ -57,7 +57,7 @@ class ActionModule(object): src = options.get('src', None) dest = options.get('dest', None) delimiter = options.get('delimiter', None) - remote_src = options.get('remote_src', True) + remote_src = utils.boolean(options.get('remote_src', 'yes')) if src is None or dest is None: result = dict(failed=True, msg="src and dest are required") @@ -65,6 +65,8 @@ class ActionModule(object): if remote_src: return self.runner._execute_module(conn, tmp, 'assemble', module_args, inject=inject, complex_args=complex_args) + elif '_original_file' in inject: + src = utils.path_dwim_relative(inject['_original_file'], 'files', src, self.runner.basedir) # Does all work assembling the file path = self._assemble_from_fragments(src, delimiter) diff --git a/library/files/assemble b/library/files/assemble index b36c6e29ffb..a8c78256e23 100644 --- a/library/files/assemble +++ b/library/files/assemble @@ -107,7 +107,11 @@ def assemble_from_fragments(src_path, delimiter=None, compiled_regexp=None): continue fragment = "%s/%s" % (src_path, f) if delimit_me and delimiter: - tmp.write("%s\n" % delimiter) + tmp.write(delimiter) + # always make sure there's a newline after the + # delimiter, so lines don't run together + if delimiter[-1] != '\n': + tmp.write('\n') if os.path.isfile(fragment): tmp.write(file(fragment).read()) delimit_me = True diff --git a/tests_new/integration/roles/test_assemble/tasks/main.yml b/tests_new/integration/roles/test_assemble/tasks/main.yml index 8aba629319d..b20551f8866 100644 --- a/tests_new/integration/roles/test_assemble/tasks/main.yml +++ b/tests_new/integration/roles/test_assemble/tasks/main.yml @@ -60,7 +60,7 @@ - "result.md5sum == '4773eac67aba3f0be745876331c8a450'" - name: test assemble with remote_src=False - assemble: src="{{output_dir}}/src" dest="{{output_dir}}/assembled4" remote_src=False + assemble: src="./" dest="{{output_dir}}/assembled4" remote_src=no register: result - name: assert the fragments were assembled without remote