You're apparently trying to keep some sort of record/audit trail of
used software versions, as comments in a docker compose yaml file.
While it will probably be possible to do what you want, the question
is: should you?
IMHO this is pretty much the opposite of what ansible was meant for...
Why not set up something better?
I can't speak for others but personally I'm not very inclined to help
with questions about such kludges.
In that respect it is also in your own interest to put the bar a
little bit higher...
Let’s say yes, it’s something to do with spaces.
We could be more specific if you tell us what parameters you’re giving to lineinfile.
Having said that, I have to agree with the previous poster: lineinfile is a poor substitute for version control, which is where history should be preserved, not cluttering up active configuration.
I agree that it would better to manage state not contents of the file.
I suggest having multiple docker compose files each pointing to the jenkins version and use Ansible to change symbolic links to the one you desire.
A list of files would be
docker-compose-jenkins:2.232.1
docker-compose-jenkins:2.303.1
docker-compose-jenkins:2.303.2
docker-compose-jenkins:2.319.2
docker-compose-jenkins:2.319.3
docker-compose-jenkins:2.332.1
Ansible would set the symlink to the desired docker-compose
Sym Link -- docker-compose.yml -> docker-compose-jenkins:2.332.1