5

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

Community
  • 1
  • 1
guettli
  • 25,042
  • 81
  • 346
  • 663
  • The output of a script will be used as a content for crontab? And will it be on same machine? You can always use salt['cmd.run'] and then have hard path of file as content/name. Though to me it seems what you are doing in script needs a different look, so some more data will help – Vishal Biyani Dec 14 '15 at 19:02
  • @vishal.biyani we use django. We activate apps/plugins by adding it to settings.INSTALLED_APPS. Every app can provide some cron-jobs. Up to now the INSTALLED_APPS list needs to be evaluated to know which cron jobs need to be installed. A script on the minion can collect each cron-jobs and create the whole output. Do you need more information? – guettli Dec 15 '15 at 09:10

1 Answers1

1

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.

OrangeDog
  • 36,653
  • 12
  • 122
  • 207