trying to modify line in yaml file spaces

trying to modify this line

image: jenkins/jenkins:2.332.1

docker-compose.yml

version: ‘3.7’
services:
jenkins:
#image: jenkins/jenkins:lts
#image: jenkins/jenkins:2.289.3
#image: jenkins/jenkins:2.303.1
#image: jenkins/jenkins:2.303.2
#image: jenkins/jenkins:2.319.2
#image: jenkins/jenkins:2.319.3
image: jenkins/jenkins:2.332.1

modify line

image: jenkins/jenkins:2.332.1

to

image: jenkins/jenkins:2.332.1

and then add
image: jenkins/jenkins:2.332.2

but my pb keeps adding it at the end of the file

maybe something to do with spaces?

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...

ok I am close now

i got this result

docker-compose.yml

version: ‘3.7’
services:
jenkins:
#image: jenkins/jenkins:lts
#image: jenkins/jenkins:2.289.3
#image: jenkins/jenkins:2.303.1
#image: jenkins/jenkins:2.303.2
#image: jenkins/jenkins:2.319.2
#image: jenkins/jenkins:2.319.3
#image: jenkins/jenkins:2.332.1
image: jenkins/jenkins:2.332.2

but i need the lines lined up

exp: ‘^\s*#\simage: jenkins/jenkins:2.332.1’

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.

There is no “exp” parameter to lineinfile. Don’t make us guess; show us what your actually doing. (You’re going to need backrefs, btw.)

ok sorry

my vars.yml

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