ansible - 如何在多个文件上使用ansible blockinfile?

标签 ansible

嗨,我想在多个文件上使用 blockinfile 函数来更改每个文件中的文本 block 。

不幸的是blockinfile不支持这个功能。有人可以帮助我吗?

最佳答案

To use blockinfile on multiple files to change blocks of text ...

您可能想要创建模板并循环 blockinfile 模块。

- blockinfile:
    marker: "# {mark} ANSIBLE MANAGED BLOCK {{ item.template }}"
    create: yes
    path: "{{ item.file }}"
    block: "{{ lookup('template', item.template) }}"
  loop: "{{ files_templates }}"

关于ansible - 如何在多个文件上使用ansible blockinfile?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53380881/

相关文章:

yaml - ansible with_items 列表列表正在变平

ansible - 针对不可用的主机运行 ansible playbook(停机/离线)

Python:打开函数无法打开带有追加的新文件

ansible - 申请become/becom_user的条件

docker - Ansible 剧本 : setup and connect to docker (authentication or permission failure)

ssh - 使用 Ansible 锁定 SSH 的最佳实践是什么?

ansible - 如何在 CentOS 8 上使用 Ansible 添加存储库

Ansible:向命令提供输入文件

ansible - Playbook 依赖项与角色依赖项

linux - 使用公共(public) SSH key 连接到本地主机失败