Bookmark this page

Guided Exercise: Managing Storage

In this exercise, you assign a new disk as an LVM physical volume to a volume group, create logical volumes and format them with XFS file systems, and mount them immediately and automatically at boot time on your managed hosts.

Outcomes

  • Use the redhat.rhel_system_roles.storage role to manage LVM volume groups and volumes.

  • Use the redhat.rhel_system_roles.storage role to create file systems.

  • Use the redhat.rhel_system_roles.storage role to control and configure mount points in /etc/fstab.

As the student user on the workstation machine, use the lab command to prepare your system for this exercise.

This command prepares your environment and ensures that all required resources are available.

[student@workstation ~]$ lab start system-storage

Procedure 9.4. Instructions

You are responsible for managing a set of web servers. You need to configure them to store web-site data on a separate file system from the configuration and log files for the web servers. This is a recommended practice.

Write a playbook to:

  • Use the /dev/vdb device as an LVM physical volume, contributing space to the volume group apache-vg.

  • Create two logical volumes named content-lv (64 MB in size) and logs-lv (128 MB in size), both backed by the apache-vg volume group.

  • Create an XFS file system on both logical volumes.

  • Mount the content-lv logical volume on the /var/www directory.

  • Mount the logs-lv logical volume on the /var/log/httpd directory.

  1. Change into the /home/student/system-storage project directory.

    [student@workstation ~]$ cd ~/system-storage
    [student@workstation system-storage]$
  2. Install the rhel_system_roles collection from the redhat-rhel_system_roles-1.19.3.tar.gz file into the collections directory in the project directory.

    1. Use the ansible-galaxy command to install the rhel_system_roles collection from the redhat-rhel_system_roles-1.19.3.tar.gz file into the collections directory.

      [student@workstation system-storage]$ ansible-galaxy collection install \
      > ./redhat-rhel_system_roles-1.19.3.tar.gz -p collections
      ...output omitted...
      redhat.rhel_system_roles:1.19.3 was installed successfully
  3. Create the storage.yml playbook. Write a play in that playbook that runs the redhat.rhel_system_roles.storage system role on the managed hosts in the webservers group. That play must configure the LVM physical volume, volume group, and logical volumes for the web servers.

    1. Create the storage.yml playbook that targets the webservers group and applies the redhat.rhel_system_roles.storage role.

      ---
      - name: Configure storage on webservers
        hosts: webservers
      
        roles:
          - name: redhat.rhel_system_roles.storage
    2. Define the storage_pools role variable for the redhat.rhel_system_roles.storage role. Use it to set the volume group name to apache-vg, the type to lvm, and specify that the disks use the /dev/vdb device.

            storage_pools:
              - name: apache-vg
                type: lvm
                disks:
                  - /dev/vdb
    3. Define the volumes variable within the storage_pools role variable.

                volumes:
    4. Create a logical volume within volumes with the name content-lv, a size of 64 MB, a file system type of xfs, and a mount point of /var/www.

                  - name: content-lv
                    size: 64m
                    mount_point: "/var/www"
                    fs_type: xfs
                    state: present
    5. Create another logical volume within volumes with the name logs-lv, a size of 128 MB, a file system type of xfs, and a mount point of /var/log/httpd.

                  - name: logs-lv
                    size: 128m
                    mount_point: "/var/log/httpd"
                    fs_type: xfs
                    state: present

      The final playbook should consist of the following content:

      ---
      - name: Configure storage on webservers
        hosts: webservers
      
        roles:
          - name: redhat.rhel_system_roles.storage
            storage_pools:
              - name: apache-vg
                type: lvm
                disks:
                  - /dev/vdb
                volumes:
                  - name: content-lv
                    size: 64m
                    mount_point: "/var/www"
                    fs_type: xfs
                    state: present
                  - name: logs-lv
                    size: 128m
                    mount_point: "/var/log/httpd"
                    fs_type: xfs
                    state: present
  4. Run the storage.yml playbook.

    [student@workstation system-storage]$ ansible-navigator run \
    > -m stdout storage.yml
    
    PLAY [Configure storage on webservers] *****************************************
    
    TASK [Gathering Facts] *********************************************************
    ok: [servera.lab.example.com]
    
    ...output omitted...
    
    TASK [rhel-system-roles.storage : make sure blivet is available] ***************
    changed: [servera.lab.example.com]
    
    ...output omitted...
    
    TASK [rhel-system-roles.storage : set up new/current mounts] *******************
    changed: [servera.lab.example.com] => (item={'src': '/dev/mapper/apache--vg-content--lv', 'path': '/var/www', 'fstype': 'xfs', 'opts': 'defaults', 'dump': 0, 'passno': 0, 'state': 'mounted'})
    changed: [servera.lab.example.com] => (item={'src': '/dev/mapper/apache--vg-logs--lv', 'path': '/var/log/httpd', 'fstype': 'xfs', 'opts': 'defaults', 'dump': 0, 'passno': 0, 'state': 'mounted'})
    
    ...output omitted...
    
    PLAY RECAP *********************************************************************
    servera.lab.example.com    : ok=21   changed=3    unreachable=0    failed=0    skipped=12   rescued=0    ignored=0
  5. Run the get-storage.yml playbook provided in the project directory to verify that the storage has been properly configured on the managed hosts in the webservers group. If it has, then information about the storage appears in the output of the playbook as highlighted in the following example:

    [student@workstation system-storage]$ ansible-navigator run \
    > -m stdout get-storage.yml
    
    PLAY [View storage configuration] **********************************************
    
    TASK [Gathering Facts] *********************************************************
    ok: [servera.lab.example.com]
    
    TASK [Retrieve physical volumes] ***********************************************
    changed: [servera.lab.example.com]
    
    TASK [Display physical volumes] ************************************************
    ok: [servera.lab.example.com] => {
        "msg": [
            "  PV         VG        Fmt  Attr PSize    PFree  ",
            "  /dev/vdb   apache-vg lvm2 a--  1020.00m 828.00m"
        ]
    }
    
    TASK [Retrieve volume groups] **************************************************
    changed: [servera.lab.example.com]
    
    TASK [Display volume groups] ***************************************************
    ok: [servera.lab.example.com] => {
        "msg": [
            "  VG        #PV #LV #SN Attr   VSize    VFree  ",
            "  apache-vg   1   2   0 wz--n- 1020.00m 828.00m"
        ]
    }
    
    TASK [Retrieve logical volumes] ************************************************
    changed: [servera.lab.example.com]
    
    TASK [Display logical volumes] *************************************************
    ok: [servera.lab.example.com] => {
        "msg": [
            "  LV         VG        Attr       LSize   Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert",
            "  content-lv apache-vg -wi-ao----  64.00m                                                    ",
            "  logs-lv    apache-vg -wi-ao---- 128.00m                                                    "
        ]
    }
    
    TASK [Retrieve mounted logical volumes] ****************************************
    changed: [servera.lab.example.com]
    
    TASK [Display mounted logical volumes] *****************************************
    ok: [servera.lab.example.com] => {
        "msg": [
            "/dev/mapper/apache--vg-content--lv on /var/www type xfs (rw,relatime,seclabel,attr2,inode64,logbufs=8,logbsize=32k,noquota)",
            "/dev/mapper/apache--vg-logs--lv on /var/log/httpd type xfs (rw,relatime,seclabel,attr2,inode64,logbufs=8,logbsize=32k,noquota)"
        ]
    }
    
    TASK [Retrieve /etc/fstab contents] ********************************************
    changed: [servera.lab.example.com]
    
    TASK [Display /etc/fstab contents] *********************************************
    ok: [servera.lab.example.com] => {
        "msg": [
            "UUID=5e75a2b9-1367-4cc8-bb38-4d6abc3964b8\t/boot\txfs\tdefaults\t0\t0",
            "UUID=fb535add-9799-4a27-b8bc-e8259f39a767\t/\txfs\tdefaults\t0\t0",
            "UUID=7B77-95E7\t/boot/efi\tvfat\tdefaults,uid=0,gid=0,umask=077,shortname=winnt\t0\t2",
            "/dev/mapper/apache--vg-content--lv /var/www xfs defaults 0 0",
            "/dev/mapper/apache--vg-logs--lv /var/log/httpd xfs defaults 0 0"
        ]
    }
    
    PLAY RECAP *********************************************************************
    servera.lab.example.com    : ok=11   changed=5    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0

Finish

On the workstation machine, change to the student user home directory and use the lab command to complete this exercise. This step is important to ensure that resources from previous exercises do not impact upcoming exercises.

[student@workstation ~]$ lab finish system-storage

This concludes the section.

Revision: rh294-9.0-c95c7de