cron - Manage cron.d and crontab entries.

Author:Dane Summers

Synopsis

Use this module to manage crontab entries. This module allows you to create named crontab entries, update, or delete them. The module includes one line with the description of the crontab entry "#Ansible: <name>" corresponding to the “name” passed to the module, which is used by future ansible/module calls to find/check the state.

Options

parameter required default choices comments
backup no
    If set, create a backup of the crontab before it is modified. The location of the backup is returned in the backup variable by this module.
    cron_file no
      If specified, uses this file in cron.d instead of an individual user's crontab.
      day no *
        Day of the month the job should run ( 1-31, *, */2, etc )
        hour no *
          Hour when the job should run ( 0-23, *, */2, etc )
          job no
            The command to execute. Required if state=present.
            minute no *
              Minute when the job should run ( 0-59, *, */2, etc )
              month no *
                Month of the year the job should run ( 1-12, *, */2, etc )
                name no
                  Description of a crontab entry.
                  reboot no no
                  • yes
                  • no
                  If the job should be run at reboot. This option is deprecated. Users should use special_time. (added in Ansible 1.0)
                  special_time no
                  • reboot
                  • yearly
                  • annually
                  • monthly
                  • weekly
                  • daily
                  • hourly
                  Special time specification nickname. (added in Ansible 1.3)
                  state no present
                  • present
                  • absent
                  Whether to ensure the job is present or absent.
                  user no root
                    The specific user whose crontab should be modified.
                    weekday no *
                      Day of the week that the job should run ( 0-6 for Sunday-Saturday, *, etc )

                      Note

                      Requires cron

                      Examples


                      # Ensure a job that runs at 2 and 5 exists.
                      # Creates an entry like "* 5,2 * * ls -alh > /dev/null"
                      - cron: name="check dirs" hour="5,2" job="ls -alh > /dev/null"
                      
                      # Ensure an old job is no longer present. Removes any job that is prefixed
                      # by "#Ansible: an old job" from the crontab
                      - cron: name="an old job" state=absent
                      
                      # Creates an entry like "@reboot /some/job.sh"
                      - cron: name="a job for reboot" special_time=reboot job="/some/job.sh"
                      
                      # Creates a cron file under /etc/cron.d
                      - cron: name="yum autoupdate" weekday="2" minute=0 hour=12
                              user="root" job="YUMINTERACTIVE=0 /usr/sbin/yum-autoupdate"
                              cron_file=ansible_yum-autoupdate
                      
                      # Removes a cron file from under /etc/cron.d
                      - cron: cron_file=ansible_yum-autoupdate state=absent
                      

                      Table Of Contents

                      Previous topic

                      capabilities - Manage Linux capabilities

                      Next topic

                      debconf - Configure a .deb package