votes up 6

Complex args containing variables cannot use bare variables (without Jinja2 delimiters), and must use the full variable style ('({var_name)}')

Package:
ansible
github stars 49704
Exception Class:
AnsibleParserError

Raise code

 dict()
        if additional_args:
            if isinstance(additional_args, string_types):
                templar = Templar(loader=None)
                if templar.is_template(additional_args):
                    final_args['_variable_params'] = additional_args
                else:
                    raise AnsibleParserError("Complex args containing variables cannot use bare variables (without Jinja2 delimiters), "
                                             "and must use the full variable style ('{{var_name}}')")
            elif isinstance(additional_args, dict):
                final_args.update(additional_args)
            else:
                raise AnsibleParserError('Complex args must be a dictionary or variable string ("{{var}}").')

        # how we normalize depends if we figured out what the module name is
        # yet.  If w
😲  Walkingbet is Android app that pays you real bitcoins for a walking. Withdrawable real money bonus is available now, hurry up! 🚶

Ways to fix

votes up 1 votes down

Summary: 

This exception is thrown when the parse function is called on an object of type ModuleArgsParser Class. When creating an instance of that class, there is an optional parameter: task_ds. This parameter is of type dictionary and it looks for certain keys, specifically action and args. The exception is thrown if the value for the key args is a bare String. To avoid this exception, wrap the string value in {{}} within the string itself.

For example: 'args' : '{{a}}'

Code to Reproduce the Error (WRONG):

import ansible.parsing.mod_args as ma
p = ma.ModuleArgsParser(task_ds={'action':'a', 'args':'a'})
p.parse()

Working Version (Fixed):

import ansible.parsing.mod_args as ma
p = ma.ModuleArgsParser(task_ds={'action':'a', 'args':'{{a}}'}) # Notice {{}}
p.parse()

Jul 08, 2021 codingcomedyig answer

Add a possible fix

Please authorize to post fix