This is the starting point where you can get the date and time of the modified file when it is managed by Salt using the Salt column .
Lets call our salt_managed variable. Create a post file as follows:
{% set managed_text = 'Salt managed: File modified on ' + salt.cmd.run('date "+%Y-%m-%d %H:%M:%S"') %} salt_managed: {{ managed_text | yaml_dquote }}
Then in the minion, when you call the pillar, you will get the following result:
$ salt-call pillar.get salt_managed local: Salt managed: File modified on 2016-10-18 11:12:40
And you can use this by adding it to the top of the configuration files, for example:
{{ pillar.get('salt_managed') }}
Update:
I found a job that might be helpful to someone. Suppose we have several states that can modify the same file. How can we know that state X is responsible for modifying this file? by following these steps:
1- I created a state like this:
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 }}"
The contents of the barfile file:
This is a new file
2- Call the state from the minion, and this will be the result:
$ 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
Currently foofile content:
This file was managed by using this salt state statedir.test This is a new file