I
I
Iceforest2021-11-29 22:21:24
Ansible
Iceforest, 2021-11-29 22:21:24

What is the best way to replace a string in docker-compose.yaml using Ansible?

there is a standard docker-compose.yaml

version: '3.1'

services:
   app:
       image: test/app
       build:
            context: ./
            dockerfile: Dockerfile
       container_name: app
       restart: always
       ports:
           - '8080:8080'


wrote in ansible:
- name: change internal port
  lineinfile:
     dest: "{{ project_path }}/docker-compose.yaml"
     regexp: '8080:8080'
     insertafter: '8080:8080'
     line: '      - 80:8080'


actually the question is how to replace it so that it is beautiful, and not 6 spaces before -80, otherwise docker-compose does not work

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Karabanov, 2021-11-29
@Iceforest

Use jinja2 templates, don't use regexps like this. Then it will be both beautiful and understandable and convenient.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question