[英]Performing multiple ansible.builtin.blockinfile tasks on the same file?
[英]How to use ansible blockinfile on multiple files?
嗨,我想對多個文件使用blockinfile函數,以更改每個文件中的文本塊。
不幸的是,blockinfile不支持此功能。 有人能幫我嗎?
在多個文件上使用blockinfile更改文本塊...
您可能要創建模板並循環blockinfile模塊。
- blockinfile:
marker: "# {mark} ANSIBLE MANAGED BLOCK {{ item.template }}"
create: yes
path: "{{ item.file }}"
block: "{{ lookup('template', item.template) }}"
loop: "{{ files_templates }}"
您可以這樣做:
- name: Add same block of text in multiple files/paths
blockinfile:
path: "{{ item.path }}"
marker: "###### {mark} Ansible Config #####"
insertafter: EOF
state: present
block: |
# Some random text comment
Some random command1
Some random command2
with_items:
- {path: '/your/path/one'}
- {path: '/your/path/two'}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.