Skip to main content
Redhat Developers  Logo
  • AI

    Get started with AI

    • Red Hat AI
      Accelerate the development and deployment of enterprise AI solutions.
    • AI learning hub
      Explore learning materials and tools, organized by task.
    • AI interactive demos
      Click through scenarios with Red Hat AI, including training LLMs and more.
    • AI/ML learning paths
      Expand your OpenShift AI knowledge using these learning resources.
    • AI quickstarts
      Focused AI use cases designed for fast deployment on Red Hat AI platforms.
    • No-cost AI training
      Foundational Red Hat AI training.

    Featured resources

    • OpenShift AI learning
    • Open source AI for developers
    • AI product application development
    • Open source-powered AI/ML for hybrid cloud
    • AI and Node.js cheat sheet

    Red Hat AI Factory with NVIDIA

    • Red Hat AI Factory with NVIDIA is a co-engineered, enterprise-grade AI solution for building, deploying, and managing AI at scale across hybrid cloud environments.
    • Explore the solution
  • Learn

    Self-guided

    • Documentation
      Find answers, get step-by-step guidance, and learn how to use Red Hat products.
    • Learning paths
      Explore curated walkthroughs for common development tasks.
    • See all learning

    Hands-on

    • Developer Sandbox
      Spin up Red Hat's products and technologies without setup or configuration.
    • Interactive labs
      Learn by doing in these hands-on, browser-based experiences.
    • Interactive demos
      Click through product features in these guided tours.

    Browse by topic

    • AI/ML
    • Automation
    • Java
    • Kubernetes
    • Linux
    • See all topics

    Training & certifications

    • Courses and exams
    • Certifications
    • Skills assessments
    • Red Hat Academy
    • Learning subscription
    • Explore training
  • Build

    Get started

    • Red Hat build of Podman Desktop
      A downloadable, local development hub to experiment with our products and builds.
    • Developer Sandbox
      Spin up Red Hat's products and technologies without setup or configuration.

    Download products

    • Access product downloads to start building and testing right away.
    • Red Hat Enterprise Linux
    • Red Hat AI
    • Red Hat OpenShift
    • Red Hat Ansible Automation Platform
    • See all products

    Featured

    • Red Hat build of OpenJDK
    • Red Hat JBoss Enterprise Application Platform
    • Red Hat OpenShift Dev Spaces
    • Red Hat Developer Toolset

    References

    • E-books
    • Documentation
    • Cheat sheets
    • Architecture center
  • Community

    Get involved

    • Events
    • Live AI events
    • Red Hat Summit
    • Red Hat Accelerators
    • Community discussions

    Follow along

    • Articles & blogs
    • Developer newsletter
    • Videos
    • Github

    Get help

    • Customer service
    • Customer support
    • Regional contacts
    • Find a partner

    Join the Red Hat Developer program

    • Download Red Hat products and project builds, access support documentation, learning content, and more.
    • Explore the benefits

Get started with the Keycloak Collection

October 10, 2024
Harsha Cherukuri
Related topics:
Automation and management
Related products:
Red Hat Ansible Automation Platform

    The article A tutorial on Middleware Automation Collections discussed setting up an Ansible Galaxy server on your control node. It also guides the use of the ansible-navigator utility and Ansible execution environment. We also went through the ansible-middleware-ee execution environment provided by the team that includes all of the Ansible Content Collections and their dependencies.

    In this tutorial, we will leverage the ansible-middleware-ee execution environment and get started using the Keycloak collection provided by the Ansible Middleware team which can help us automate the Keycloak single sign-on (SSO) server.

    Step 1: Use the ansible-navigator utility

    Let’s use the execution environment and the ansible-navigator utility to perform the automation and provisioning of Keycloak collection. The ansible-middleware-ee execution environment provided by the Ansible Middleware team includes all the latest collections in the image. To browse the list of the latest collections included in the image, run the following command:

    $ ansible-navigator --eei quay.io/ansible-middleware/ansible-middleware-ee:latest collections
    Name                       Version Shadowed Type     Path
     0│ansible.builtin            2.15.3  False    contained /usr/local/lib/python3.9/si
     1│ansible.netcommon          5.1.2   False    contained /usr/share/ansible/collecti
     2│ansible.posix              1.5.4   False    contained /usr/share/ansible/collecti
     3│ansible.utils              2.10.3  False    contained /usr/share/ansible/collecti
     4│community.general          7.3.0   False    contained /usr/share/ansible/collecti
     5│middleware_automation.amq  1.3.8   False    contained /usr/share/ansible/collecti
     6│middleware_automation.amq_s0.0.5   False    contained /usr/share/ansible/collecti
     7│middleware_automation.commo1.1.2   False    contained /usr/share/ansible/collecti
     8│middleware_automation.infin1.2.0   False    contained /usr/share/ansible/collecti
     9│middleware_automation.jws  1.2.3   False    contained /usr/share/ansible/collecti
    10│middleware_automation.keycl1.2.8   False    contained /usr/share/ansible/collecti
    11│middleware_automation.redha1.2.2   False    contained /usr/share/ansible/collecti
    12│middleware_automation.wildf1.3.4   False    contained /usr/share/ansible/collecti

    Step 2: Set up the inventory

    Let's now set up a Keycloak instance. Create an inventory file that includes a Red Hat Enterprise Linux 8 instance, the IP address of the instance, and login information for Ansible to access it. We are using SSH keys instead of passwords. These SSH keys are created on the controller node and we provide the path of the private key in the inventory file. Our inventory file looks like this:

    [keycloak]
    keycloak-0 ansible_host=10.0.10.1 ansible_user=root ansible_ssh_private_key_file=”path to your private key”

    Step 3: Install and configure Keycloak single sign-on

    Here is the playbook keycloak.yml which will install and configure single sign-on. This playbook automatically downloads and installs the Keycloak, and allows you to define realm, client, and users. See below:

    ---
    - name: Playbook for Keycloak Hosts
      hosts: all
      vars:
        keycloak_admin_password: "remembertochangeme"
        keycloak_realm: TestRealm
      collections:
        - middleware_automation.keycloak
      roles:
        - keycloak
      tasks:
     - name: Keycloak Realm Role
       ansible.builtin.include_role:
         name: keycloak_realm
       vars:
         keycloak_client_default_roles:
           - TestRoleAdmin
           - TestRoleUser
         keycloak_client_users:
           - username: TestUser
             password: password
             client_roles:
               - client: TestClient
                 role: TestRoleUser
                 realm: "{{ keycloak_realm }}"
           - username: TestAdmin
             password: password
             client_roles:
               - client: TestClient
                 role: TestRoleUser
                 realm: "{{ keycloak_realm }}"
               - client: TestClient
                 role: TestRoleAdmin
                 realm: "{{ keycloak_realm }}"
         keycloak_realm: TestRealm
         keycloak_clients:
           - name: TestClient
             roles: "{{ keycloak_client_default_roles }}"
             realm: "{{ keycloak_realm }}"
             public_client: "{{ keycloak_client_public }}"
             web_origins: "{{ keycloak_client_web_origins }}"
             users: "{{ keycloak_client_users }}"
             client_id: TestClient

    Step 4: Run the Ansible Playbook

    Now, run the Ansible Playbook using ansible-navigator and the execution environment to configure Keycloak on the remote node as follows:

    $ansible-navigator --eei quay.io/ansible-middleware/ansible-middleware-ee:latest run keycloak.yml -i inventory -m stdout --become

    Once the Keycloak service is deployed, SSH into the instance to check the service status:

    ssh root@10.0.10.1 systemctl status keycloak.service

    We can also check if the port is accessible or not using the below command:

    # curl -I http://localhost:9990/health
    HTTP/1.1 200 OK
    Connection: keep-alive
    Content-Type: application/json
    Content-Length: 283

    Conclusion

    In this tutorial, we have demonstrated how to use the Ansible middleware execution environment and set up Keycloak using the Ansible Content Collections for Keycloak. You can check out the other collections and demos within the GitHub organization ansible-middleware and the Middleware Automation Collections website.

    Related Posts

    • Get started with the Wildfly collection

    • Red Hat Extends JBoss Middleware to OpenShift

    • Automate your SSO with Ansible and Keycloak

    • How to restrict user authentication in Keycloak during identity brokering

    • Keycloak Identity Brokering with OpenShift

    • How to integrate Spring Boot 3, Spring Security, and Keycloak

    Recent Posts

    • Federated identity across the hybrid cloud using zero trust workload identity manager

    • Confidential virtual machine storage attack scenarios

    • Introducing virtualization platform autopilot

    • Integrate zero trust workload identity manager with Red Hat OpenShift GitOps

    • Best Practice Configuration and Tuning for Linux and Windows VMs

    What’s up next?

    Explore essential Ansible concepts, terminology, and tools, then set up your environment to start writing your first Ansible playbook.

    Start the activity
    Red Hat Developers logo LinkedIn YouTube Twitter Facebook

    Platforms

    • Red Hat AI
    • Red Hat Enterprise Linux
    • Red Hat OpenShift
    • Red Hat Ansible Automation Platform
    • See all products

    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
    © 2026 Red Hat

    Red Hat legal and privacy links

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

    Chat Support

    Please log in with your Red Hat account to access chat support.