在Ansible中,可以使用template模块来追加文件数据。以下是一个示例解决方案:
template.j2的模板文件,内容如下:{{ ansible_managed }}
# 追加的数据
{{ file_data }}
playbook.yml的Ansible剧本文件,内容如下:- name: 使用模板模块追加文件数据
hosts: your_host
gather_facts: false
vars:
file_data: |
This is some additional data that will be appended to the file.
tasks:
- name: 追加文件数据
template:
src: template.j2
dest: /path/to/your/file
owner: your_owner
group: your_group
mode: 0644
在上面的剧本中,file_data变量包含将要追加到文件中的数据。template模块将使用template.j2模板文件将数据追加到目标文件中。
ansible-playbook playbook.yml
运行后,file_data中的数据将被追加到目标文件的末尾。
请注意,/path/to/your/file应替换为您要追加数据的实际文件路径,并替换your_owner和your_group为文件的所有者和组。