Ansible 2.9.21: unwanted escape char “\” is added in shell command

Use single quotes in the grep command.

grep "[ ]\+{{ newTomcatVer }}$"

When you use double quotes, the shell will try to do variable expansion, meaning it will try to make sense of $". This is coming out as $\" because the shell doesn't recognize $" as a parameter it can expand, so it tries to guess what you wanted and escapes the quotation mark.

There's no real reason to do shell parameter expansion here, so you can place the regex in single quotes to solve the problem. The shell will not attempt to do parameter expansion and will treat the $ literally.

grep '[ ]\+{{ newTomcatVer }}$'