Ansible help regex

14 views
Skip to first unread message

Numi

unread,
Apr 3, 2018, 8:00:06 PM4/3/18
to Ansible Project
Hello, I was wondering if someone can possible help me with my Ansible playbook. I have a file called myfile.yml with a line that contains an image. Example line:

service:
    blahblah
    image
: myoldimagename
    blahblah


I want to change everything after the word "image: " with a configuration line, however I'm having trouble. For example, I want to replace "myoldimagename" with "mynewline". I don'e want to match "myoldimagename" explicitly because that may be different. 

    - name: Configure myfile.yml
      replace
:
        path
: /data/config/myfile.yml
        regexp
: "(?<=image: ).*"
        replace
: \1mynewline
        backup
: yes

Philippe Eveque

unread,
Apr 4, 2018, 1:51:57 PM4/4/18
to ansible...@googlegroups.com
see https://www.regular-expressions.info/lookaround.html  for explanations.
lookaround is not consuming any characters.

try on https://regex101.com/ to make it concrete about what is matched or not

HTH
Phil



--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-project+unsubscribe@googlegroups.com.
To post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/4f2d6e8a-516c-4b34-bf30-d33670de654e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages