Skip to main content
Redhat Developers  Logo
  • Products

    Featured

    • Red Hat Enterprise Linux
      Red Hat Enterprise Linux Icon
    • Red Hat OpenShift AI
      Red Hat OpenShift AI
    • Red Hat Enterprise Linux AI
      Linux icon inside of a brain
    • Image mode for Red Hat Enterprise Linux
      RHEL image mode
    • Red Hat OpenShift
      Openshift icon
    • Red Hat Ansible Automation Platform
      Ansible icon
    • Red Hat Developer Hub
      Developer Hub
    • View All Red Hat Products
    • Linux

      • Red Hat Enterprise Linux
      • Image mode for Red Hat Enterprise Linux
      • Red Hat Universal Base Images (UBI)
    • Java runtimes & frameworks

      • JBoss Enterprise Application Platform
      • Red Hat build of OpenJDK
    • Kubernetes

      • Red Hat OpenShift
      • Microsoft Azure Red Hat OpenShift
      • Red Hat OpenShift Virtualization
      • Red Hat OpenShift Lightspeed
    • Integration & App Connectivity

      • Red Hat Build of Apache Camel
      • Red Hat Service Interconnect
      • Red Hat Connectivity Link
    • AI/ML

      • Red Hat OpenShift AI
      • Red Hat Enterprise Linux AI
    • Automation

      • Red Hat Ansible Automation Platform
      • Red Hat Ansible Lightspeed
    • Developer tools

      • Red Hat Trusted Software Supply Chain
      • Podman Desktop
      • Red Hat OpenShift Dev Spaces
    • Developer Sandbox

      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
    • Secure Development & Architectures

      • Security
      • Secure coding
    • Platform Engineering

      • DevOps
      • DevSecOps
      • Ansible automation for applications and services
    • Automated Data Processing

      • AI/ML
      • Data Science
      • Apache Kafka on Kubernetes
      • View All Technologies
    • Start exploring in the Developer Sandbox for free

      sandbox graphic
      Try Red Hat's products and technologies without setup or configuration.
    • Try at no cost
  • Learn

    Featured

    • Kubernetes & Cloud Native
      Openshift icon
    • Linux
      Rhel icon
    • Automation
      Ansible cloud icon
    • Java
      Java 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

    • API Catalog
    • Product Documentation
    • Legacy Documentation
    • Red Hat Learning

      Learning image
      Boost your technical skills to expert-level with the help of interactive lessons offered by various Red Hat Learning programs.
    • Explore Red Hat Learning
  • 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

Get started with the Keycloak Collection

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

Share:

    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

    • How to run AI models in cloud development environments

    • How Trilio secures OpenShift virtual machines and containers

    • How to implement observability with Node.js and Llama Stack

    • How to encrypt RHEL images for Azure confidential VMs

    • How to manage RHEL virtual machines with Podman Desktop

    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

    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

    Red Hat legal and privacy links

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

    Report a website issue