I want to create a cron tab with salt.
I found this method:
salt.states.cron.file(name, source_hash='', user='root', template=None, context=None, replace=True, defaults=None, env=None, backup='', **kwargs)
Provides file.managed-like functionality (templating, etc.) for a pre-made crontab file, to be assigned to a given user.
name
The source file to be used as the crontab. This source file can be hosted on either the salt master server, or on an HTTP or FTP server. For files hosted on the salt file server, if the file is located on the master in the directory named spam, and is called eggs, the source string is salt://spam/eggs
https://docs.saltstack.com/en/latest/ref/states/all/salt.states.cron.html#salt.states.cron.file
I want to use the output of a script which gets called on the minion as source.
How can I do this?
Update
It looks like this is not possible up to now. I created an issue: https://github.com/saltstack/salt/issues/29698
There's no way to use output of a script as a file source. However, there are a couple of other ways to manage your system with salt.
Option 1: Use a cmd.script
state to run your script (managed in Salt) and have it write the crontab itself. You can use onchanges
to only trigger this when you change the list of installed apps.
Option 2: Use jinja templating to generate the cron.present
states you require. You can call the script from jinja, or replicate what it does using the available execution modules.
If you're not managing the script yourself, and it's installed via some other method, then you can use cmd.run
instead.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With