Created
November 27, 2018 16:59
-
-
Save dreampuf/8c51eb0bc8187c08ecaa3e4db394f183 to your computer and use it in GitHub Desktop.
Convert cronjob file to SaltStack state
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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