[Ansible] 将被Ansible管理的信息嵌入到使用模板生成的文件注释中
在template模块的文档中写明,如果在模板文件中写上{{ ansible_managed }},那么这个文件将被展开为一个字符串,表明该文件是由Ansible管理的(所以不要手动修改)。
如果是用于注释的文件,则在模板文件(*.j2)中写入以下内容。
# {{ ansible_managed }}
我們來使用電子信箱epel安裝Ansible 1.2.2後,可以在 /etc/ansible/ansible.cfg 找到預設設定,內容如下:
# format of string $ansible_managed available within Jinja2 templates, replacing
# {file}, {host} and {uid} with template filename, host and owner respectively.
# The resulting string is passed through strftime(3) so it may contain any
# time-formatting specifiers.
#
# Example: ansible_managed = DONT TOUCH {file}: call {uid} at {host} for changes
ansible_managed = Ansible managed: {file} modified on %Y-%m-%d %H:%M:%S by {uid} on {host}