saltstack / salt

Software to automate the management and configuration of any infrastructure or application at scale. Get access to the Salt software package repository here:
https://repo.saltproject.io/
Apache License 2.0
14.11k stars 5.47k forks source link

[BUG] Cron state breaks on cronjobs with identical commands but unique identifier #61194

Open Borromini opened 2 years ago

Borromini commented 2 years ago

Description Cron state is breaking on multiple identical commands to be executed at different times, despite the identifier being different, which (as per https://github.com/saltstack/salt/issues/7979) should differentiate the commands from one another.

Setup SLS:

``` # Cron jobs. # # Remarks: # - rtcwake does not need a -t prefix via logger. # # TODO # - xx # - xx # - xx include: - cron # System availibility /usr/sbin/rtcwake -m off --date 06:45 2>&1 | /usr/bin/logger: cron.present: - identifier: rtcwake.cron - minute: '30' - hour: '01' - dayweek: '1-5' - comment: Shut down at 01:30 and bring up at 06:45 on weekdays # Dagelijkse snapshots en synchronisatie naar Amalthea. /sbin/zfs snapshot ichi/work@"$(/bin/date +\%Y\%m\%d)"| /usr/bin/logger -t zfs-snapshot: cron.present: - identifier: zfs.snapshot.cron - minute: '55' - hour: '23' - dayweek: '*' - comment: Create daily snapshot /usr/local/sbin/zfs-snapshot-backup compress | /usr/bin/logger -t zfs-snapshot-backup: cron.present: - identifier: zfs.snapshot.compress.cron - minute: '05' - hour: '00' - dayweek: '*' - comment: Create compressed deltas /usr/local/sbin/zfs-snapshot-backup post | /usr/bin/logger -t zfs-snapshot-backup: cron.present: - identifier: zfs.snapshot.post.cron - user: xyz - minute: '45' - hour: '07' - dayweek: '*' - comment: Backup verification # Weekly local backups with reminders about timeframe /usr/local/sbin/zfs-snapshot-backup warn | /usr/bin/logger -t zfs-snapshot-backup: cron.present: - identifier: zfs.snapshot.local.friday.warn.cron - minute: '55' - hour: '18' - dayweek: '5' - comment: Weekly local eS-ATA backup (reminder) /usr/local/sbin/zfs-snapshot-backup local | /usr/bin/logger -t zfs-snapshot-backup: cron.present: - identifier: zfs.snapshot.local.friday.cron - minute: '00' - hour: '19' - dayweek: '5' - comment: Weekly local eS-ATA backup (reminder) /usr/local/sbin/zfs-snapshot-backup warn | /usr/bin/logger -t zfs-snapshot-backup: cron.present: - identifier: zfs.snapshot.local.saturday.warn.cron - minute: '55' - hour: '07' - dayweek: '6' - comment: Weekly local eS-ATA backup (saturday) /usr/local/sbin/zfs-snapshot-backup local | /usr/bin/logger -t zfs-snapshot-backup: cron.present: - identifier: zfs.snapshot.local.saturday.cron - minute: '00' - hour: '08' - dayweek: '6' - comment: Weekly local eS-ATA backup (saturday) # Bi-weekly scrub. /usr/local/sbin/zpm scrub | /usr/bin/logger -t zfs-scrub: cron.present: - identifier: zfs.scrub.cron - minute: '35' - hour: '01' - dayweek: '6' - comment: Bi-weekly scrub /usr/local/sbin/zpm report | /usr/bin/logger -t zfs-scrub: cron.present: - identifier: zfs.scrub.report.cron - minute: '30' - hour: '16' - dayweek: '6' - comment: Mail bi-weekly scrub results # Daily restart for Salt client. /bin/systemctl restart salt-minion.service: cron.present: - identifier: salt.restart.daily.cron - minute: '00' - hour: '18' - dayweek: '*' - comment: Daily restart ```

Please be as specific as possible and give set-up details.

Steps to Reproduce the behavior Create cron state file with identical commands, but with different identifiers (and optionally timestamps for execution).

Expected behavior Salt not breaking. This worked on older releases.

Versions Report

salt --versions-report (Provided by running salt --versions-report. Please also mention any differences in master/minion versions.) ``` Salt Version: Salt: 3002.6 Dependency Versions: cffi: Not Installed cherrypy: Not Installed dateutil: 2.8.1 docker-py: Not Installed gitdb: Not Installed gitpython: Not Installed Jinja2: 2.11.3 libgit2: 1.1.0 M2Crypto: Not Installed Mako: 1.1.3 msgpack: 1.0.0 msgpack-pure: Not Installed mysql-python: Not Installed pycparser: Not Installed pycrypto: 2.6.1 pycryptodome: 3.9.7 pygit2: 1.4.0 Python: 3.9.2 (default, Feb 28 2021, 17:03:44) python-gnupg: Not Installed PyYAML: 5.3.1 PyZMQ: 20.0.0 smmap: Not Installed timelib: Not Installed Tornado: 4.5.3 ZMQ: 4.3.4 System Versions: dist: debian 11 bullseye locale: utf-8 machine: x86_64 release: 5.10.0-9-amd64 system: Linux version: Debian GNU/Linux 11 bullseye ```

Additional context Error spit out is this:

porphyrion.srv:
    Data failed to compile:
----------
    Rendering SLS 'base:cron.porphyrion' failed: while constructing a mapping
  in "<unicode string>", line 12, column 1
found conflicting ID '/usr/local/sbin/zfs-snapshot-backup warn | /usr/bin/logger -t zfs-snapshot-backup'
  in "<unicode string>", line 71, column 1
welcome[bot] commented 2 years ago

Hi there! Welcome to the Salt Community! Thank you for making your first contribution. We have a lengthy process for issues and PRs. Someone from the Core Team will follow up as soon as possible. In the meantime, here’s some information that may help as you continue your Salt journey. Please be sure to review our Code of Conduct. Also, check out some of our community resources including:

There are lots of ways to get involved in our community. Every month, there are around a dozen opportunities to meet with other contributors and the Salt Core team and collaborate in real time. The best way to keep track is by subscribing to the Salt Community Events Calendar. If you have additional questions, email us at saltproject@vmware.com. We’re glad you’ve joined our community and look forward to doing awesome things with you!

dseomn commented 4 months ago

From the error, it looks like the issue is having two states with the same ID, not two cron jobs with the same command. I.e., I think changing from the first example below to the second should work. (But I haven't tested it, this is just a drive-by comment while I was looking for something else.)

duplicate ID:

duplicate command:
  cron.present:
  - identifier: duplicate.command.1
duplicate command:
  cron.present:
  - identifier: duplicate.command.2

no duplicate ID:

duplicate command 1:
  cron.present:
  - name: duplicate command
  - identifier: duplicate.command.1
duplicate command 2:
  cron.present:
  - name: duplicate command
  - identifier: duplicate.command.2