Skip to main content
Redhat Developers  Logo
  • Products

    Platforms

    • Red Hat Enterprise Linux
      Red Hat Enterprise Linux Icon
    • Red Hat AI
      Red Hat AI
    • Red Hat OpenShift
      Openshift icon
    • Red Hat Ansible Automation Platform
      Ansible icon
    • View All Red Hat Products

    Featured

    • Red Hat build of OpenJDK
    • Red Hat Developer Hub
    • Red Hat JBoss Enterprise Application Platform
    • Red Hat OpenShift Dev Spaces
    • Red Hat OpenShift Local
    • Red Hat Developer Sandbox

      Try Red Hat products and technologies without setup or configuration fees for 30 days with this shared Openshift and Kubernetes cluster.
    • Try at no cost
  • Technologies

    Featured

    • AI/ML
      AI/ML Icon
    • Linux
      Linux Icon
    • Kubernetes
      Cloud icon
    • Automation
      Automation Icon showing arrows moving in a circle around a gear
    • View All Technologies
    • Programming Languages & Frameworks

      • Java
      • Python
      • JavaScript
    • System Design & Architecture

      • Red Hat architecture and design patterns
      • Microservices
      • Event-Driven Architecture
      • Databases
    • Developer Productivity

      • Developer productivity
      • Developer Tools
      • GitOps
    • Automated Data Processing

      • AI/ML
      • Data Science
      • Apache Kafka on Kubernetes
    • Platform Engineering

      • DevOps
      • DevSecOps
      • Ansible automation for applications and services
    • Secure Development & Architectures

      • Security
      • Secure coding
  • Learn

    Featured

    • Kubernetes & Cloud Native
      Openshift icon
    • Linux
      Rhel icon
    • Automation
      Ansible cloud icon
    • AI/ML
      AI/ML Icon
    • View All Learning Resources

    E-Books

    • GitOps Cookbook
    • Podman in Action
    • Kubernetes Operators
    • The Path to GitOps
    • View All E-books

    Cheat Sheets

    • Linux Commands
    • Bash Commands
    • Git
    • systemd Commands
    • View All Cheat Sheets

    Documentation

    • Product Documentation
    • API Catalog
    • Legacy Documentation
  • Developer Sandbox

    Developer Sandbox

    • Access Red Hat’s products and technologies without setup or configuration, and start developing quicker than ever before with our new, no-cost sandbox environments.
    • Explore Developer Sandbox

    Featured Developer Sandbox activities

    • Get started with your Developer Sandbox
    • OpenShift virtualization and application modernization using the Developer Sandbox
    • Explore all Developer Sandbox activities

    Ready to start developing apps?

    • Try at no cost
  • Blog
  • Events
  • Videos

Patch updates on RHEL servers with Ansible Automation Platform 2.4

April 15, 2024
Himanshu Yadav
Related topics:
Automation and managementLinux
Related products:
Red Hat Ansible Automation PlatformRed Hat Enterprise Linux

Share:

    In today's dynamic IT landscape, efficient management of server infrastructure is paramount. Regular patching is essential for maintaining security, stability, and compliance across enterprise environments. Red Hat Enterprise Linux (RHEL) servers are widely used in business-critical operations, making timely patching a crucial task. Manual patching can be time-consuming and error-prone, especially for large server deployments. In this technical blog, we'll explore how to streamline patch updates of SELinux on RHEL servers using Red Hat Ansible Automation Platform 2.4.

    Prerequisites

    This article requires the following prerequisites:

    • Installed Ansible Automation Platform.
    • One or more RHEL machines. 
    • Basic knowledge of RHEL.
    • Basic knowledge of Ansible.
    • A no-cost Red Hat Developer Subscription for Individuals.

    Register RHEL system on Red Hat Hybrid Cloud Console

    To initiate registration and scanning of your RHEL machine on the Red Hat Hybrid Cloud Console, execute the following commands:

    [root@server ~]# insights-client --register 
    [root@server ~]# rhc connect
    Connecting server to Red Hat.
    This might take a few seconds.
    
    Username: user1
    Password:
    
    ● Connected to Red Hat Subscription Management
    ● Connected to Red Hat Insights
    ● Activated the Red Hat connector daemon
    
    Manage your Red Hat connector systems: https://red.ht/connector

    When accessing the Red Hat Hybrid Cloud platform, navigate to Insights -> System. This will provide you with the hostname of your RHEL server, as demonstrated in Figure 1.

    rhel scan
    Figure 1: Listed RHEL server on Insights portal.

    Click on the listed host and select the Vulnerabilities option from the tabs. This will display a list of all vulnerabilities present in your system, categorized by severity level.

    Search for "SELinux" in the search box to filter the available vulnerabilities related to SELinux, as depicted in Figure 2.

    selinux patch
    Figure 2: Vulnerabilities related to SELinux.

    Click on the name of the vulnerability (RHBA-20236328) to access the respective RPM package necessary to patch the issue. Incorporate this RPM package into the playbook, following the example provided below.

    Patch-update.yaml

    ---
    - name: Red Hat Enterprise linux patch update
      hosts: rhel-server.example.com
      gather_facts: yes
      tasks:
        - name: selinux patch update
          dnf:
            name:  https://access.cdn.redhat.com/content/origin/rpms/selinux-policy/38.1.23/1.el9_3.2/fd431d51/selinux-policy-38.1.23-1.el9_3.2.noarch.rpm
            state: present
        
        - name:  Update all packages
          dnf:
            name: "*"
            state: latest

    This approach enables you to automate patching tasks using Ansible, which serves as the enterprise automation solution within Ansible Automation Platform. The instructions outlined below will guide you through executing the patch playbook via Ansible Automation Platform.

    To execute the playbook, it's essential to satisfy the dependencies such as Machine Credentials, Project, Inventory, and Template, for that following instructions are given.

    Create machine credentials

    To enable Ansible Automation Platform access to the RHEL server that requires patch updates, it is necessary to define the accessibility credentials of that machine, such as private keys, root permissions, and admin user credentials. Figure 3 depicts this.

    1. From the left menu select the Credentials.
    2. Give it a Name.
    3. Select credentials type as Machine credentials.
    4. Under Type Details add the username of the RHEL server.
    5. Add SSH private key.
    6. Define sudo as Privilege Escalation Method.
    7. Add root as Privilege Escalation Username.
    8. Click on the Save button.
    credentials
    Figure 3: Machine credentials configuration.

    Add inventories

    An inventory is a collection of hosts against which jobs can be launched, the same as an Ansible inventory file.

    1. From the left menu, select Inventories.
    2. Click on Add button and select Add Inventories option.
    3. Enter a Name to the inventory.
    4. Next, add the host to the inventory. Check the connectivity with the server using the ping module by clicking the Run Command button.
    5. Select the Run Command first.
    6. Select the ping module from the drop-down and choose Machine Credentials. 
    7. Keep the rest of the details as default (you can change the settings per your requirement).
    8. Click Launch.

    After successful run of the ping module you will get the pong response in the jobs. If it fails, kindly check the credentials and inventories, and launch it again.

    Create a Project

    A project is a logical collection of Ansible playbooks, represented in the automation controller. You can manage playbooks and playbook directories by either placing them manually under the project base path on your controller server, or by placing your playbooks into a source code management (SCM) system supported by the automation controller, including Git, Subversion, and Mercurial. Project configuration is shown in Figure 4.

    1. Select the Project option under Resources from the left menu.
    2. Define Name of Project.
    3. Under Source Control Type select Git.
    4. In Source Control URL, define the URL of the GitHub repository.
    5. In the Source Control Branch define the main branch.
    6. Click on the Save button.
    preoject
    Figure 4: Project configuration.

    Create and launch the template

    A Job template is a definition and set of parameters for running an Ansible job. Job templates are useful to execute the same job many times. Job templates also encourage the reuse of Ansible Playbook content and collaboration between teams.

    Create a template that will execute the job for us, as shown in Figure 5.

    1. From the left menu, select Templates and create a New template.
    2. Click on Add button and select the Add job template.
    3. Name the template.
    4. Select the inventory.
    5. Select a Project.
    6. Choose the playbook you want to run in the template. 
    7. Choose Credentials.
    8. Click on the Save button and then click the Launch button.
    template
    Figure 5: Template creation.

    In the jobs section, you will find the following output after the successful execution of the playbook on the RHEL server.

    Identity added: /runner/artifacts/12/ssh_key_data (/runner/artifacts/12/ssh_key_data)
    PLAY [Red Hat Enterprice linux patch update] ***********************************
    TASK [Gathering Facts] *********************************************************
    ok: [rhel-server.example.com]
    TASK [selinux patch update] ****************************************************
    changed: [rhel-server.example.com]
    TASK [Update all packages] *****************************************************
    changed: [rhel-server.example.com]
    PLAY RECAP *********************************************************************
    rhel-server.example.com           : ok=3    changed=2    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0   

    Have a closer look in the job logs as shown in Figure 6.

    output
    Figure 6: After playbook execution output in JSON format.

    After successfully executing the playbook on the Ansible Automation Platform, we need to revisit the Red Hat Hybrid Cloud portal to verify if the vulnerability has been resolved, as depicted in Figure 7.

    scan again
    Figure 7: Checking for resolved vulnerabilities on Insights portal.

    What's next in your automation journey?

    In this article, you learned how to do a patch update on the Red Hat Enterprise Linux server with the help of Ansible Automation Platform.

    Now that you have set up Ansible Automation Platform, explore our interactive labs at Red Hat Developer.  

    Last updated: September 27, 2024

    Related Posts

    • Secure RHEL systems using Ansible Automation Platform

    • What's new in Ansible Automation Platform 2.4

    • Install containerized Ansible Automation Platform on RHEL 9.2

    • How custom SELinux policies secure servers and containers

    • How to deploy applications using Ansible Automation Platform

    • How to install Ansible Tower on Red Hat OpenShift

    Recent Posts

    • How to enable Ansible Lightspeed intelligent assistant

    • Why some agentic AI developers are moving code from Python to Rust

    • Confidential VMs: The core of confidential containers

    • Benchmarking with GuideLLM in air-gapped OpenShift clusters

    • Run Qwen3-Next on vLLM with Red Hat AI: A step-by-step guide

    What’s up next?

    Get a preview of the Red Hat Certified Engineer (RHCE) Ansible Automation Study Guide (O’Reilly), which covers key Ansible concepts for your system administration needs.

    Get the e-book
    Red Hat Developers logo LinkedIn YouTube Twitter Facebook

    Products

    • Red Hat Enterprise Linux
    • Red Hat OpenShift
    • Red Hat Ansible Automation Platform

    Build

    • Developer Sandbox
    • Developer Tools
    • Interactive Tutorials
    • API Catalog

    Quicklinks

    • Learning Resources
    • E-books
    • Cheat Sheets
    • Blog
    • Events
    • Newsletter

    Communicate

    • About us
    • Contact sales
    • Find a partner
    • Report a website issue
    • Site Status Dashboard
    • Report a security problem

    RED HAT DEVELOPER

    Build here. Go anywhere.

    We serve the builders. The problem solvers who create careers with code.

    Join us if you’re a developer, software engineer, web designer, front-end designer, UX designer, computer scientist, architect, tester, product manager, project manager or team lead.

    Sign me up

    Red Hat legal and privacy links

    • About Red Hat
    • Jobs
    • Events
    • Locations
    • Contact Red Hat
    • Red Hat Blog
    • Inclusion at Red Hat
    • Cool Stuff Store
    • Red Hat Summit
    © 2025 Red Hat

    Red Hat legal and privacy links

    • Privacy statement
    • Terms of use
    • All policies and guidelines
    • Digital accessibility

    Report a website issue