Cannot use sed inside it

Hello, I have a little bug with ansible parser I can’t execute this code in ansible:

This code works on shell

`
echo “INSERT INTO scripts VALUES (‘1’, ‘install-debian’, ‘$(cat startupscripts/install-debian.sh | sed "s#’#‘’#g”)', 0);" | docker exec -i --user postgres $(docker-compose ps -q postgres) psql baremetal

`

So I escaped it like this

`

“echo "INSERT INTO scripts VALUES (‘1’, ‘install-debian’, ‘$(cat startupscripts/install-debian.sh | sed "s#’#‘’#g")', 0);" | docker exec -i --user postgres $(docker-compose ps -q postgres) psql baremetal”

`

But this doesn’t work can you tell me why ?