# trying to modify line in yaml file spaces

**URL:** <https://forum.ansible.com/t/trying-to-modify-line-in-yaml-file-spaces/36617>\
**Category:** Ansible Project\
**Created:** [May 11, 2022, 6:17pm UTC](https://forum.ansible.com/t/trying-to-modify-line-in-yaml-file-spaces/36617 "2022-05-11T18:17:16Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tony\_Wong](https://avatars.discourse-cdn.com/v4/letter/t/3ab097/32.png) [@Tony\_Wong](https://forum.ansible.com/u/Tony_Wong)\
**Post date:** [May 11, 2022, 6:17pm UTC](https://forum.ansible.com/t/trying-to-modify-line-in-yaml-file-spaces/36617/1 "2022-05-11T18:17:16Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![dnmvisser](https://avatars.discourse-cdn.com/v4/letter/d/8e8cbc/32.png) [@dnmvisser](https://forum.ansible.com/u/dnmvisser)\
**Post date:** [May 11, 2022, 6:39pm UTC](https://forum.ansible.com/t/trying-to-modify-line-in-yaml-file-spaces/36617/2 "2022-05-11T18:39:28Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Tony\_Wong](https://avatars.discourse-cdn.com/v4/letter/t/3ab097/32.png) [@Tony\_Wong](https://forum.ansible.com/u/Tony_Wong)\
**Post date:** [May 11, 2022, 6:44pm UTC](https://forum.ansible.com/t/trying-to-modify-line-in-yaml-file-spaces/36617/3 "2022-05-11T18:44:41Z")

</div>

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\*#_\s_image: jenkins/jenkins:2.332.1’

---

<div class="post-metadata">

**Author:** ![utoddl](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/utoddl/32/249_2.png) [@utoddl](https://forum.ansible.com/u/utoddl)\
**Post date:** [May 11, 2022, 6:49pm UTC](https://forum.ansible.com/t/trying-to-modify-line-in-yaml-file-spaces/36617/4 "2022-05-11T18:49:22Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![utoddl](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/utoddl/32/249_2.png) [@utoddl](https://forum.ansible.com/u/utoddl)\
**Post date:** [May 11, 2022, 6:53pm UTC](https://forum.ansible.com/t/trying-to-modify-line-in-yaml-file-spaces/36617/5 "2022-05-11T18:53:05Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Tony\_Wong](https://avatars.discourse-cdn.com/v4/letter/t/3ab097/32.png) [@Tony\_Wong](https://forum.ansible.com/u/Tony_Wong)\
**Post date:** [May 11, 2022, 7:03pm UTC](https://forum.ansible.com/t/trying-to-modify-line-in-yaml-file-spaces/36617/6 "2022-05-11T19:03:46Z")

</div>

ok sorry

my vars.yml

---

<div class="post-metadata">

**Author:** ![shearn](https://avatars.discourse-cdn.com/v4/letter/s/ba8739/32.png) [@shearn](https://forum.ansible.com/u/shearn)\
**Post date:** [May 12, 2022, 4:36pm UTC](https://forum.ansible.com/t/trying-to-modify-line-in-yaml-file-spaces/36617/7 "2022-05-12T16:36:16Z")

</div>

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
