WelcomeUser Guide
ToSPrivacyCanary
DonateBugsLicense

©2024 Poal.co

215

I had a problem at work with trying to remove cron jobs using Ansible. The way Ansible manages cron jobs is it sticks a particular comment above the job when it is added. Removal is easy then, just get rid of the job under the comment.

What if the job wasn't added by Ansible with that comment above? Well, we have the shell. Behold it in all its glory:

crontab -l | grep -v job_to_remove.sh | crontab -

We list the crontab, pipe it to grep to remove the job from the output, then we pipe that right back into crontab. How slick is that?

I had a problem at work with trying to remove cron jobs using Ansible. The way Ansible manages cron jobs is it sticks a particular comment above the job when it is added. Removal is easy then, just get rid of the job under the comment. What if the job wasn't added by Ansible with that comment above? Well, we have the shell. Behold it in all its glory: `crontab -l | grep -v job_to_remove.sh | crontab -` We list the crontab, pipe it to grep to remove the job from the output, then we pipe that right back into crontab. How slick is that?

(post is archived)

[–] 0 pt

Yeah, it's like that. I'm removing them because we're going to Ansible scheduled jobs, so the Ansible execution nodes will be running the formerly cron jobs against all of the servers.