Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature Request: Template variable to explain source of a file #37068

Closed
guettli opened this issue Oct 18, 2016 · 11 comments
Closed

Feature Request: Template variable to explain source of a file #37068

guettli opened this issue Oct 18, 2016 · 11 comments
Labels
Core relates to code central or existential to Salt Feature new functionality including changes to functionality and code refactors, etc. Renderers stale
Milestone

Comments

@guettli
Copy link
Contributor

guettli commented Oct 18, 2016

Description of Issue/Question

I want to know where config files on a minion come from.

Example

# /etc/postfix/main.cf
# source salt/mailserver/files/etc/postfix/main.cf.sls installed on 2016-10-18 12:42
....

I am lazy, and don't want to maintain above information myself.

There is a cool feature for ansible. The template system provides a variable {{ ansible_managed }}
This gets expanded to the source of the file and a time stamp.
See: http://docs.ansible.com/ansible/intro_configuration.html#ansible-managed

It would be great to have such a feature in salt, too.

Related StackO question: http://stackoverflow.com/questions/39747351/saltstack-reverse-engineering-where-a-file-comes-from

What do you think?

@mostafahussein
Copy link
Contributor

mostafahussein commented Oct 18, 2016

For a better following up I will add my comment in here.

First as a temporary solution you can create your own Pillar for example lets call it salt_managed and its value could be like this:

{% set managed_text = 'Salt managed: File modified on ' + salt.cmd.run('date "+DATE: %Y-%m-%d TIME: %H:%M:%S"') %}

salt_managed: {{ managed_text | yaml_dquote }}

Then on the minion you will get this result:

$ salt-call pillar.get salt_managed
local:
    Salt managed: File modified on DATE: 2016-10-18 TIME: 11:12:40

And you can use this by adding it on the top of your config files for example like this

{{ pillar.get('salt_managed') }}

The main problem with this solution that i cannot get the user who executed a state from the event bus, if there is a way to achieve that it would be very helpful then.

what do you think ?

@guettli
Copy link
Contributor Author

guettli commented Oct 18, 2016

@mostafahussein implementing this via pillar looks good. I don't understand why you want to get the user who executed a state. At least in my environment it will always be root. I would like to know the source of this file or snippet (file.blockreplace)

@Ch3LL
Copy link
Contributor

Ch3LL commented Oct 18, 2016

I think this is a great idea. I'll approve as a feature request thanks

@Ch3LL Ch3LL added Feature new functionality including changes to functionality and code refactors, etc. Core relates to code central or existential to Salt Renderers labels Oct 18, 2016
@Ch3LL Ch3LL added this to the Approved milestone Oct 18, 2016
@mostafahussein
Copy link
Contributor

mostafahussein commented Oct 18, 2016

@guettli my environment has multiple user and we are using ssh keys. so i will be able to know who have updated the file and when.
For the source of the file you might add as you said on stackoverflow, if i found another way i will let you know

Should I add the above implementation as answer to your question ?

@mostafahussein
Copy link
Contributor

mostafahussein commented Oct 18, 2016

@Ch3LL Is there a way to access the event bus during state execution ? or even by creating a custom module ?

Update:

1- Can we get the file reference during execution ? (I can see it in state.show.sls results but i wish if it could be called inside the managed file itself)
2- Can we get the user who executed the formula ? (I know it could be done using returners but i mean during the execution)

@guettli
Copy link
Contributor Author

guettli commented Oct 19, 2016

@mostafahussein yes, please answer my StackO question with your sample implementation. It's a good starting point. I hope there is a way to figure out which file gets processed at the moment.

@mostafahussein
Copy link
Contributor

@guettli I have added it to your question. and if there is any other solutions then i will keep you updated.

@lorengordon
Copy link
Contributor

@mostafahussein, to answer your first question, maybe try {{ tplfile }}. There are a few context variables that may be useful here.

https://github.com/saltstack/salt/blob/develop/salt/utils/templates.py#L141-L145

@guettli guettli changed the title Feature Request: Template varaible to explain source of a file Feature Request: Template variable to explain source of a file Oct 20, 2016
@stale
Copy link

stale bot commented Jul 13, 2018

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

If this issue is closed prematurely, please leave a comment and we will gladly reopen the issue.

@stale stale bot added the stale label Jul 13, 2018
@stale stale bot closed this as completed Jul 20, 2018
@andreasnuesslein
Copy link

I would like to see such a feature too.

@mostafahussein 's approach with the pillars is nice but has the downside that it always update the templates, even if nothing changes inside. That's not exactly what I would want in general.
Is there a solution to that?

@kees-closed
Copy link

I would like to see such a feature too.

@mostafahussein 's approach with the pillars is nice but has the downside that it always update the templates, even if nothing changes inside. That's not exactly what I would want in general. Is there a solution to that?

Indeed, it totally is not what most want. {{ ansible_managed }} is brilliant, hopefully it will one day be available for Salt as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Core relates to code central or existential to Salt Feature new functionality including changes to functionality and code refactors, etc. Renderers stale
Projects
None yet
Development

No branches or pull requests

6 participants