One of the great things about Ansible is being able to use Jinja filters both in templates and in yaml files.
I came across a not so great thing today though. Running a play I got the following error:
template error while templating string: expected token 'end of print statement', got ':'
But the error was 'thrown' by a task I haven't changed in ages.
The task does use a template - but that hadn't changed either. Mystery!
It turns out that I had used a variable assignment elsewhere in a vars file referred to by a subsequent task within the same play.
This assignment used a Jinja filter (lookup) - (simplied example for the sake of this post).
The adaptation was to turn the variable assignment into a dictionary so I could specify the source, destination and mode of the file(s).
This was the error - the filter needs to have double braces around it to be recognised as such - I had left the double braces around the whole element and this threw the error.
The correct assignment in this case is:
This will get the contents of sourcefile (in this case a string for a single file path) and place them in the variable src.
It appears that the templating 'engine' was awoken by the failed task and validated vars used in the subsequent task.
So if you get this error - don't assume it is within the task that it is reported.
Best start looking at recent changes and work back!
A good argument for 'commit often' so your changes are easier to review.
info [at] blue-bag.com
Telephone: 0843 2894522
Blue-Bag HQ: The Garage, Manor Farm Chilcompton, Radstock Somerset, BA3 4HP, United Kingdom
Telephone: (+44) 01761 411542
Blue-Bag Brighton: Unit 35 Level 6 North, New England House New England Street, Brighton BN1 4GH United Kingdom