From 80df2135e903bc167b70cd1a45e8d4eb803e87ed Mon Sep 17 00:00:00 2001 From: James Cammarata Date: Wed, 30 Jul 2014 14:18:06 -0500 Subject: [PATCH] Fix parsing of tasks with variable module names Also adding an integration test for same. --- lib/ansible/playbook/task.py | 5 +++-- .../roles/test_good_parsing/tasks/main.yml | 11 +++++++++++ .../integration/roles/test_good_parsing/vars/main.yml | 2 ++ 3 files changed, 16 insertions(+), 2 deletions(-) create mode 100644 test/integration/roles/test_good_parsing/vars/main.yml diff --git a/lib/ansible/playbook/task.py b/lib/ansible/playbook/task.py index ecdb1df76a..4d3eab382f 100644 --- a/lib/ansible/playbook/task.py +++ b/lib/ansible/playbook/task.py @@ -17,6 +17,7 @@ from ansible import errors from ansible import utils +from ansible.module_utils.splitter import split_args import os import ansible.utils.template as template import sys @@ -234,13 +235,13 @@ class Task(object): self.notify = [ self.notify ] # split the action line into a module name + arguments - tokens = self.action.split(None, 1) + tokens = split_args(self.action) if len(tokens) < 1: raise errors.AnsibleError("invalid/missing action in task. name: %s" % self.name) self.module_name = tokens[0] self.module_args = '' if len(tokens) > 1: - self.module_args = tokens[1] + self.module_args = " ".join(tokens[1:]) import_tags = self.module_vars.get('tags',[]) if type(import_tags) in [int,float]: diff --git a/test/integration/roles/test_good_parsing/tasks/main.yml b/test/integration/roles/test_good_parsing/tasks/main.yml index bb87c025c1..fc302dbd8f 100644 --- a/test/integration/roles/test_good_parsing/tasks/main.yml +++ b/test/integration/roles/test_good_parsing/tasks/main.yml @@ -152,4 +152,15 @@ that: - complex_param == "this is a param in a complex arg with double quotes" +- name: test variable module name + action: "{{ variable_module_name }} msg='this should be debugged'" + register: result + +- debug: var=result + +- name: assert the task with variable module name ran + assert: + that: + - result.invocation.module_name == "debug" + - result.msg == "this should be debugged" diff --git a/test/integration/roles/test_good_parsing/vars/main.yml b/test/integration/roles/test_good_parsing/vars/main.yml new file mode 100644 index 0000000000..ea7a0b846e --- /dev/null +++ b/test/integration/roles/test_good_parsing/vars/main.yml @@ -0,0 +1,2 @@ +--- +variable_module_name: debug