Why is the outcome 30 instead of hello030?
O padrão do módulo lineinfile é backrefs: false . Seu regexp='^(hello)world$' corresponde ao conteúdo inteiro de arquivo . Literal de line='30' substitui o conteúdo.
How to solve it?
- Ative os backrefs com
backrefs: true - Use um grupo nomeado em
line:
Um backref seguido por números não funcionará como esperado. Você precisará de um grupo nomeado. por exemplo. \g<1>
- name: Replace the world
lineinfile:
dest: file
regexp: '^(hello)world$'
line: '\g<1>030'
backrefs: true