Ansible Archiving

30 minutes
  • 4 Learning Objectives

About this Hands-on Lab

Being able to do normal system tasks, such as performing archives and backups, is one of the key skills for success with using Ansible. The ability to do this is also an objective now, on the *Red Hat Certified Ansible Specialist* exam.

In this hands-on lab we will use a playbook with the archive module. We’ll make it archive a folder, then transfer the resulting archives from several servers back to the Ansible control server. This will be used for backup purposes.

Note: Ansible has been setup and configured for use on the Control server and two nodes. This will save time when doing the hands-on lab.

*This course is not approved or sponsored by Red Hat.*

Learning Objectives

Successfully complete this lab by achieving the following learning objectives:

Sign onto the Ansible Control Node Server as cloud_user and Change to the ansible User. Test to Ensure Ansible Has Been Set up for You

Sign into the server called Ansible Control Node using the cloud_user and change to the ansible user via the su – ansible command.

Test that ansible is working via an ad-hoc command.

A possible command to use is the following:

ansible all -m ping

Note: It may take several minutes after the start of the lab for the test to work as expected.

Create an Ansible Playbook Called backup-logs.yml. The Playbook Should Create a Compressed Backup of the /var/log Folder on Each of the Nodes

The Ansible playbook should create a backup of the /var/log folder to the /home/ansible folder and call
the compressed copy of the log files, logs.tar.gz.

Using Another Ansible Module, Copy the Compressed Log Files to the Control Node. Ensure the Name Is Unique and Related to Which Node It Has Come From

Using the fetch module, fetch from each node a copy of the compressed log file back to the control node.
The file on the control node should be a name that relates to which node it came from.

Uncompress One of the Files That Has Been Downloaded and Make Sure It Is a Copy of the Files That Are in the /var/log Folder on the Node

Uncompress one of the archived files that has been copied to the control node and test to ensure it is a valid copy of the files as they exist on the node.

Additional Resources

The Scenario:

We are doing some work for a charity that does not have the money to pay for a commercial backup solution. We have told them we are able to back up some folders and transfer them to a central location using Ansible. We have been asked to show a proof of concept by archiving and downloading a folder from all the servers.

The Task:

In this hands-on lab we will make use of the archive module to archive a folder on our Nodes and transfer the resulting compressed file to our Ansible control node.

To summarize, using an Ansible playbook you must do the following:

  1. Create a playbook called backup-logs.yml
  2. The playbook should archive the /var/log folder on each node to a file in the ansible user's home directory.
  3. Transfer the archived file to the control node with the name logbackup- and the node's hostname as part of the file name.

Here are some important things to take into consideration while completing each task:

  • For convenience, Ansible is already on the control node. If we connect to the server by clicking on the Public IP address in a browser, we need to make sure we change to the ansible user with the su - ansible command.
  • The user ansible is present on all servers, with appropriate shared keys for access to managed servers from the control node. Make sure to use the ansible user to complete the commands.
  • The ansible user has the same password as cloud_user.
  • The default Ansible inventory has been configured for with the appropriate hosts and groups.
  • /etc/hosts entries are present on control1 for the managed servers.

What are Hands-on Labs

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.

Sign In
Welcome Back!

Psst…this one if you’ve been moved to ACG!

Get Started
Who’s going to be learning?