- Lab
- A Cloud Guru
Tackling Ansible Scheduling with the `at` Command
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.*
Path Info
Table of Contents
-
Challenge
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.
-
-
Challenge
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
-
Challenge
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
-
Challenge
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
-
Challenge
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.
-
What's a lab?
Hands-on Labs are real environments created by industry experts to help you learn. These environments help you gain knowledge and experience, practice without compromising your system, test without risk, destroy without fear, and let you learn from your mistakes. Hands-on Labs: practice your skills before delivering in the real world.
Provided environment for hands-on practice
We will provide the credentials and environment necessary for you to practice right within your browser.
Guided walkthrough
Follow along with the author’s guided walkthrough and build something new in your provided environment!
Did you know?
On average, you retain 75% more of your learning if you get time for practice.