SysV cron (as found on e.g. Solaris and derivatives) works a bit differently than vixie/ISC cron in regards to crontabs other than a user’s self-modifiable crontab. Rather than reading /etc/cron.d/* and merging them into a system crontab (where the time spec must be followed by a username), a directory exists at /etc/cron.d/crontabs where crontabs named for a user can be placed by an admin, and those jobs will be run as the named user.
You can actually create these per-user system crontabs on SysV systems using the cron module like: cron: cron_file="crontabs/<user>" ...
but unfortunately the cron module makes the assumption that if you are using the cron_file
param, the file should be in the <timespec> <user> <command>
format, whereas in SysV cron, these per-user system crontabs should be in the <timespec> <command>
format.
I’m happy to provide a PR implementing a fix for this, but I need to know what the preferred implementation would be. Here are a few ideas:
- Add a new boolean to
cron
likeinclude_user
controlling the inclusion of the user field, that defaults to an automatic value based on the use ofcron_file
but can be forced on or off. - Check if
(ansible_os_family == 'Solaris' and cron_file.startswith('crontabs/'))
and don’t include the username field if true. - Add a new boolean to
cron
likeuse_system_dir
that, if set, in the absence of thecron_files
param, will edit files in/etc/cron.d/crontabs/<user>
.
And finally, I think I like this one best because it’s the cleanest and most broadly applicable:
- Add a new param to
cron
likespool_dir
that, if set to a directory, overrides /etc/cron.d as the directory in which crontabs will be created, AND: - If cron_file is set, create the file as
<spool_dir>/<cron_file>
and use the<timespec> <username> <command>
format - If cron_file is unset, create the file as
<spool_dir>/<user>
and use the<timespec> <command>
format.
Thanks,
–nate