I need to create ansible task which inserts a string value into database. The problem is that the string value may contain all sorts of spaces, quotes, etc.
I am going to do approximately this:
- name: Insert record
command: mysql db_name -e "INSERT INTO table(column) VALUES ('{{ the_value }}');"
the_value
variable contains the string, but as I mentioned there are all sorts of spaces and quotes in it. So, it should be escaped.
The standard ansible quote
filter probably is not appropriate here, because it escapes strings to be used in shell commands, but I do not use shell.
There is somewhat similar question here: Insert data into mysql tables using ansible , but it doesn't help to solve the escaping problem.