Skip to content

Instantly share code, notes, and snippets.

@dreampuf
Created November 27, 2018 16:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dreampuf/8c51eb0bc8187c08ecaa3e4db394f183 to your computer and use it in GitHub Desktop.
Save dreampuf/8c51eb0bc8187c08ecaa3e4db394f183 to your computer and use it in GitHub Desktop.
Convert cronjob file to SaltStack state
import re
cronjob_content = """ PAST YOUR CRONJOB HERE """
cronjob_regex = re.compile(r'^([^#]\S*?) (\S+) (\S+) (\S+) (\S+)\s+(.+)$')
for n, (minute, hour, daymonth, month, dayweek, exp) in enumerate([i.groups() for i in map(cronjob_regex.search, d.splitlines()) if i], 1):
print "cronjob-%02d:" % n
print " cronjob.present:"
for k, v in {"minute": minute, "hour": hour, "daymonth": daymonth, "month": month, "dayweek": dayweek}.items():
if v != "*":
print " - %s: %s" % (k, v)
print " - name: %s" % exp
print
cronjob-01:
cronjob.present:
- minute: */5
- name: date
cronjob-02:
cronjob.present:
- hour: 0
- minute: 02
- name: bash -c "[[ -f /tmp/exist_file ]]"
cronjob-03:
cronjob.present:
- minute: */5
- name: echo saltstack &>/dev/null
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment