Многократное добавление одной и той же строки в файл yaml (ansible playbook) - PullRequest
0 голосов
/ 27 февраля 2020

Я хочу добавить одну строку несколько раз в указанном c между строками. Я попытался с моей пьесой, но только один раз добавил к последней, и он должен добавить ту же строку с From Earth.

Моя пьеса

- name: Update the file
  lineinfile:
    dest: /sample/config.file
    insertafter: ' Earth .* '
    line: '    This is template'

My исходный файл

Hello World
   [From Earth]
Hello World
   [From Earth]
Hello World
   [From Earth]
Hello World
   [From Earth]

Вывод My Desire

Hello World
   [From Earth]
   This is template
Hello World
   [From Earth]
   This is template
Hello World
   [From Earth]
   This is template
Hello World
   [From Earth]
   This is template

1 Ответ

1 голос
/ 27 февраля 2020

Попробуйте replace:

 - name: Replace
   replace:
       path: file.txt
       regexp: 'Earth]\n(?!{{repl_str}})'
       replace: 'Earth]\n{{repl_str}}'
   vars:
     repl_str: '   This is template\n'
...