mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
Fix parsing of tasks with variable module names
Also adding an integration test for same.
This commit is contained in:
parent
189824dd76
commit
80df2135e9
3 changed files with 16 additions and 2 deletions
|
@ -17,6 +17,7 @@
|
||||||
|
|
||||||
from ansible import errors
|
from ansible import errors
|
||||||
from ansible import utils
|
from ansible import utils
|
||||||
|
from ansible.module_utils.splitter import split_args
|
||||||
import os
|
import os
|
||||||
import ansible.utils.template as template
|
import ansible.utils.template as template
|
||||||
import sys
|
import sys
|
||||||
|
@ -234,13 +235,13 @@ class Task(object):
|
||||||
self.notify = [ self.notify ]
|
self.notify = [ self.notify ]
|
||||||
|
|
||||||
# split the action line into a module name + arguments
|
# split the action line into a module name + arguments
|
||||||
tokens = self.action.split(None, 1)
|
tokens = split_args(self.action)
|
||||||
if len(tokens) < 1:
|
if len(tokens) < 1:
|
||||||
raise errors.AnsibleError("invalid/missing action in task. name: %s" % self.name)
|
raise errors.AnsibleError("invalid/missing action in task. name: %s" % self.name)
|
||||||
self.module_name = tokens[0]
|
self.module_name = tokens[0]
|
||||||
self.module_args = ''
|
self.module_args = ''
|
||||||
if len(tokens) > 1:
|
if len(tokens) > 1:
|
||||||
self.module_args = tokens[1]
|
self.module_args = " ".join(tokens[1:])
|
||||||
|
|
||||||
import_tags = self.module_vars.get('tags',[])
|
import_tags = self.module_vars.get('tags',[])
|
||||||
if type(import_tags) in [int,float]:
|
if type(import_tags) in [int,float]:
|
||||||
|
|
|
@ -152,4 +152,15 @@
|
||||||
that:
|
that:
|
||||||
- complex_param == "this is a param in a complex arg with double quotes"
|
- 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"
|
||||||
|
|
||||||
|
|
2
test/integration/roles/test_good_parsing/vars/main.yml
Normal file
2
test/integration/roles/test_good_parsing/vars/main.yml
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
---
|
||||||
|
variable_module_name: debug
|
Loading…
Reference in a new issue