嗨,我想在多个文件上使用 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
loop:
- {path: '/your/path/one'}
- {path: '/your/path/two'}