There are multiple ways. If you want to do it “correctly”, you set state: absent
on all cronjobs and run the playbook:
- name: Add in cronjob to run every 30 mins to update do cool things
cron:
name: "Run cool.py"
user: cooluser
state: absent
You need to set them for each cronjob you created, they are matched by name
. Check the docs of the cron module.
If you just want to remove all the crontabs for a certain user, you can ssh to that box and run crontab -r -u cooluser
. This will remove all jobs for cooluser
, but leave everything in /etc/
untouched. But ansible does not add anything there.
If you want to do that, but use ansible, you can use the command module:
- name: remove all cronjobs for user cooluser
command: crontab -r -u cooluser
The first one is the one you should use in a production playbook. The other two can be used, if you just want to do a one-time cleanup to start fresh.
You can also check crontab -l -u cooluser
to see all currently available cronjobs and crontab -e -u cooluser
to edit them.
CLICK HERE to find out more related problems solutions.