Skip to main content

Using Ansible Modules to Manage Filesystems in Your Environment

Hands-On Lab

 

Photo of Rob Marti

Rob Marti

Linux Training Architect I in Content

Length

00:30:00

Difficulty

Intermediate

Requirements change, and datacenters evolve. Being able to manage storage configurations on the fly is an important skill. Ansible allows for that using the lvg, lvol, filesystem, and mount modules. This lab will allow you to practice using those modules.

What are Hands-On Labs?

Hands-On Labs are scenario-based learning environments where learners can practice without consequences. Don't compromise a system or waste money on expensive downloads. Practice real-world skills without the real-world risk, no assembly required.

Using Ansible Modules to Manage Filesystems in Your Environment

Introduction

Requirements change, and datacenters evolve. Being able to manage storage configurations on the fly is an important skill. Ansible allows for that using the lvg, lvol, filesystem, and mount modules. This lab will allow you to practice using those modules.

The Scenario

Management has purchased a new application, which of course needs database access. Our Database team has requested that a new disk be allocated and configured, to make room for this additional requirement.

Write a playbook that configures /dev/xvdg to have 10G of disk space in a logical volume named AppDB2. Make sure it's formatted using XFS, and mounted at /mnt/appdb2.

Logging In

Use the credentials provided on the hands-on lab page to get into Server1 to begin with. Since we need root privileges, let's just run sudo -i right off and become root.

Set up the New Disk with LVM, and Use the Logical Volume Name AppDB2

We're going to create disks.yml using whichever editor we like, and put this at the top of the file:

---
- name: Disks playbook
  hosts: dbservers
  become: yes

  tasks:

The first section, the one that will create the LVG, should look like this:

   - name: Create the Volume Group
     lvg:
      vg: RHCE
      pvs: /dev/xvdg

   - name: Create Logical Volume
     lvol:
      lv: AppDB2
      vg: RHCE
      size: 10G
      pvs: /dev/xvdg
      state: present

Format the Disk Using XFS

This playbook section will format the disk, and should look similar to this:

   - name: Format the disk
     filesystem:
      dev: /dev/RHCE/AppDB2
      fstype: xfs

Mount the Disk

This section of the playbook will mount the disk, and should look like this:

   - name: Mount the disk
     mount:
      fstype: xfs
      src: /dev/RHCE/AppDB2
      state: mounted
      path: /mnt/appdb2

Run the Playbook

As long as we don't have any typos in our playbook, we should see all of the successful task output march across the screen once we run:

ansible-playbook disks.yml

If we run that command a second time, we'll see that nothing changed, because everything got created and manipulated on the first pass. To double check, log into dbserver1:

ssh ansible@dbserver1

Now check to see if our new partition is in there:

df -h

We should see a line in the output showing /dev/mapper/RHCE-AppDB2 being mounted at /mnt/appdb2.

Conclusion

We've finished. We created a playbook that creates a new LVG, formats the disk in it to the XFS filesystem, and then mounts it. Congratulations!