|
1 | 1 | # Schedules
|
| 2 | + |
| 3 | +The schedule function in Semaphore allows to automate the execution of templates (e.g. playbook runs) at predefined intervals. This feature allows to implement routine automation tasks, such as regular backups, compliance checks, system updates, and more. |
| 4 | + |
| 5 | +## Setup and Configuration |
| 6 | + |
| 7 | +### Accessing the Schedule Feature |
| 8 | + |
| 9 | +1. Log in to your Ansible Semaphore web interface |
| 10 | +2. Navigate to the "Schedule" tab in the main navigation menu |
| 11 | +3. Click the "New Schedule" button in the top right corner to create a new schedule |
| 12 | + |
| 13 | + |
| 14 | + |
| 15 | +### Creating a New Schedule |
| 16 | + |
| 17 | +When creating a new schedule, you'll need to configure the following options: |
| 18 | + |
| 19 | +| Field | Description | |
| 20 | +|-------|-------------| |
| 21 | +| Name | A descriptive name for the scheduled task | |
| 22 | +| Template | The specific Task Template to execute | |
| 23 | +| Timing | Either in cron format for more fexibility or using the built-in options for common intervals | |
| 24 | + |
| 25 | +  |
| 26 | + |
| 27 | +### Cron Format Syntax |
| 28 | + |
| 29 | +The schedule uses standard cron syntax with five fields: |
| 30 | + |
| 31 | +``` |
| 32 | +┌─────── minute (0-59) |
| 33 | +│ ┌────── hour (0-23) |
| 34 | +│ │ ┌───── day of month (1-31) |
| 35 | +│ │ │ ┌───── month (1-12) |
| 36 | +│ │ │ │ ┌───── day of week (0-6) (Sunday=0) |
| 37 | +│ │ │ │ │ |
| 38 | +│ │ │ │ │ |
| 39 | +* * * * * |
| 40 | +``` |
| 41 | + |
| 42 | +Examples: |
| 43 | +- `*/15 * * * *` - Run every 15 minutes |
| 44 | +- `0 2 * * *` - Run at 2:00 AM every day |
| 45 | +- `0 0 * * 0` - Run at midnight on Sundays |
| 46 | +- `0 9 1 * *` - Run at 9:00 AM on the first day of every month |
| 47 | + |
| 48 | +Very helpful cron expression generator: [https://crontab.guru/](https://crontab.guru/) |
| 49 | + |
| 50 | +## Use Cases |
| 51 | + |
| 52 | +### System Maintenance |
| 53 | + |
| 54 | +```yaml |
| 55 | +# Example playbook for system updates |
| 56 | +--- |
| 57 | +- hosts: all |
| 58 | + become: yes |
| 59 | + tasks: |
| 60 | + - name: Update apt cache |
| 61 | + apt: |
| 62 | + update_cache: yes |
| 63 | + |
| 64 | + - name: Upgrade all packages |
| 65 | + apt: |
| 66 | + upgrade: yes |
| 67 | + |
| 68 | + - name: Remove dependencies that are no longer required |
| 69 | + apt: |
| 70 | + autoremove: yes |
| 71 | +``` |
| 72 | +
|
| 73 | +Schedule this playbook to run weekly during off-hours to ensure systems stay up-to-date. |
| 74 | +
|
| 75 | +### Backup Operations |
| 76 | +
|
| 77 | +Create schedules for database backups with different frequencies: |
| 78 | +- Daily backups that retain for one week |
| 79 | +- Weekly backups that retain for one month |
| 80 | +- Monthly backups that retain for one year |
| 81 | +
|
| 82 | +### Compliance Checks |
| 83 | +
|
| 84 | +Schedule regular compliance scans to ensure systems meet security requirements: |
| 85 | +
|
| 86 | +```yaml |
| 87 | +# Example compliance check playbook |
| 88 | +--- |
| 89 | +- hosts: all |
| 90 | + tasks: |
| 91 | + - name: Run compliance checks |
| 92 | + script: /path/to/compliance_script.sh |
| 93 | + |
| 94 | + - name: Collect compliance reports |
| 95 | + fetch: |
| 96 | + src: /var/log/compliance-report.log |
| 97 | + dest: reports/{{ inventory_hostname }}/ |
| 98 | + flat: yes |
| 99 | +``` |
| 100 | +
|
| 101 | +### Environment Provisioning and Cleanup |
| 102 | +
|
| 103 | +For development or testing environments. Schedule cloud environment creation in the morning and teardown in the evening to optimize costs. |
| 104 | +
|
| 105 | +## Best Practices |
| 106 | +
|
| 107 | +* Use descriptive names for schedules that indicate both function and timing (e.g. "Weekly-Backup-Sunday-2AM") |
| 108 | +* Avoid scheduling too many resource-intensive tasks concurrently |
| 109 | +* Consider the effect of long-running scheduled tasks on other schedules |
| 110 | +* Test schedules with short intervals before setting up production schedules with longer intervals |
| 111 | +* Document the purpose and expected outcomes of scheduled tasks |
0 commit comments