ruby - Chef-solo create cron based on node.name -
at moment need install staggered crons based on hostname recipe installs clamac. have small example works end product need work on hundreds of different hostnames ascending numbers. server example: myserver-db[1-12], anotherserver-acc[1-9].
cron 'clam-scan-weekly staggered 1' only_if {node.name == 'myserver-db1' || 'myserver-db3' } minute 30 hour 22 weekday 1 command '/usr/bin/clamscan --exclude-dir="/dev/|/proc/|/run/|/sys/" -l clamscan.log -r /' user 'root' end cron 'clam-scan-weekly staggered 2' only_if {node.name == 'myserver-db2' || 'myserver-db4' } minute 30 hour 22 weekday 1 command '/usr/bin/clamscan --exclude-dir="/dev/|/proc/|/run/|/sys/" -l clamscan.log -r /' user 'root' end
the end goal create 3 of 4 staggered cron jobs based on hostnames. looked ruby_blocks , might do-able there must easier way perhaps. hoping globbing work doesnt...thank help!
so underlying issue x == 'a' || 'b'
wrote x == 'a' || x == 'b'
meant, different.
to solve without bajillion lines of copy-paste though:
cron 'whatever' # other properties here. minute node.name.hash % 60 end
Comments
Post a Comment