Being able to schedule tasks in Ansible is a valuable skill. This is shown by the fact that it is an objective of the *Red Hat Certified Ansible Specialist* exam. The `at` command and its associated commands (`atq` and `atrm`) can be used to schedule tasks in Linux-based systems or those that support the use of the `at` command. The `at` command is useful for scheduling one-time tasks. In this hands-on lab, we will make use of the `at` module to create scheduled tasks and show how to set and remove a task from the list of jobs.
*This course is not approved or sponsored by Red Hat.*
Learning Objectives
Successfully complete this lab by achieving the following learning objectives:
- Log in to the Ansible Control Node Server and Change to the `ansible` User
- Sign in to the Ansible Control Node server using the
cloud_user
credentials, and change to theansible
user. Test that Ansible is working:
ansible all -m ping
Note: It may take several minutes after the start of the lab for the test to work as expected.
- Sign in to the Ansible Control Node server using the
- Create and Run a Playbook Called `install-at.yml` that Installs, Enables, and Starts the `at` Service on All Nodes
- Create a playbook called
install-at.yml
that will install theat
service on all nodes. - Enable the
atd
service and start the service as part of the playbook. - Run the playbook and ensure it installs, enables, and starts the service correctly.
- Create a playbook called
- Create a Playbook Called `at-scheduled-task.yml` to Perform a Task on the Nodes in 20 Minutes
- Using the
at
module, create a playbook calledat-scheduled-task.yml
that adds a scheduled task to the nodes. - The job should run in 20 minutes. The task to run is
df -h > /tmp/diskspace
.
- Using the
- Run the `at-scheduled-task` Playbook and Test Each Node to Ensure the Task Is Scheduled
- Use the
atq
command to ensure thedf -h
task has been scheduled.
- Use the
- Create a Playbook Called `remove-at-task.yml` to Remove the Previously Scheduled Task
- The
remove-at-task.yml
playbook should remove the task that was set in theat-scheduled-task.yml
playbook. We can test with the
atq
command to ensure the task has been removed.Note: If they have not, we must troubleshoot why they have not been removed.
- The