簡體   English   中英

多次將同一行添加到 yaml 文件中(ansible playbook)

[英]Multiple times adding same line into yaml file (ansible playbook)

我想在特定的行之間多次添加一行。 我嘗試使用我的劇本,但只添加到最后一個劇本,它應該添加與 From Earth 相同的行。

我的劇本

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

我的初始文件

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

我的願望輸出

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

嘗試replace

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM