這是一個起點,您可以通過使用Salt Pillar來獲取由Salt管理的修改文件的日期和時間。
讓我們打電話給我們的變量salt_managed
。上附庸
{% set managed_text = 'Salt managed: File modified on ' + salt.cmd.run('date "+%Y-%m-%d %H:%M:%S"') %}
salt_managed: {{ managed_text | yaml_dquote }}
然後當你調用的支柱,你會得到以下結果:創建一個支柱文件中像下面
$ salt-call pillar.get salt_managed
local:
Salt managed: File modified on 2016-10-18 11:12:40
你就可以把它的頂部使用例如你這樣的配置文件:
{{ pillar.get('salt_managed') }}
更新:
我找到了工作這可能對某人有用。可以說我們有多個狀態可以修改同一個文件。我們如何知道State X負責修改該文件?通過執行以下步驟:
1-我已經創建了一個狀態像這樣的:
Create a File:
file.managed:
- name: /path/to/foofile
- source: salt://statedir/barfile
Add file header:
file.prepend:
- name: /path/to/foofile
- text: "This file was managed by using this salt state {{ sls }}"
barfile的內容是:
This is a new file
2-呼叫從僕從的狀態和這將是結果:
$ salt-call state.sls statedir.test
local:
----------
ID: Create a File
Function: file.managed
Name: /path/to/foofile
Result: True
Comment: File /path/to/foofile updated
Started: 07:50:45.254994
Duration: 1034.585 ms
Changes:
----------
diff:
New file
mode:
0644
----------
ID: Add file header
Function: file.prepend
Name: /path/to/foofile
Result: True
Comment: Prepended 1 lines
Started: 07:50:46.289766
Duration: 3.69 ms
Changes:
----------
diff:
---
+++
@@ -1,1 +1,2 @@
+This file was managed by using this salt state statedir.test
This is a new file
Summary for local
------------
Succeeded: 2 (changed=2)
Failed: 0
------------
Total states run: 2
目前的foofile
的內容是:
This file was managed by using this salt state statedir.test
This is a new file
這似乎很難實施。你爲什麼不把這個註釋放入你的文件? –
@ ChristopheDrevet-Droguet爲什麼我不把自己的評論置入文件中?我很懶。我想自動化所有可以自動化的東西。這就像代碼中的註釋:由於代碼的演變,它們早晚都是謊言,但評論卻沒有。 – guettli
而不是閱讀vim中的二進制文件,爲什麼不直接閱讀狀態,只是檢查他們是否有預期的結果? – dahrens