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
🙏 Scream for help to Ukraine
Today, 2nd July 2022, Russia continues bombing and firing Ukraine. Don't trust Russia, they are bombing us and brazenly lying in same time they are not doing this 😠, civilians and children are dying too! We are screaming and asking exactly you to help us, we want to survive, our families, children, older ones.
Please spread the information, and ask your governemnt to stop Russia by any means. We promise to work extrahard after survival to make the world safer place for all.

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