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.
    • Guided learning
      Receive custom learning paths powered by our AI assistant.
    • 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

Automate your Quarkus deployment using Ansible

June 1, 2023
Romain Pelisse
Related topics:
Automation and managementJavaKubernetes
Related products:
Red Hat build of QuarkusRed Hat Ansible Automation Platform

    In this article, we’ll explain how to use Ansible to build and deploy a Quarkus application. Quarkus is an exciting, lightweight Java development framework designed for cloud and Kubernetes deployments, and Red Hat Ansible Automation Platform  is one of the most popular automation tools and a star product from Red Hat.

    Set up your Ansible environment

    Before discussing how to automate a Quarkus application deployment using Ansible, we need to ensure the prerequisites are in place. First, you have to install Ansible on your development environment. On a Fedora or a Red Hat Enterprise Linux machine, this is achieved easily utilizing the dnf package manager:

    $ dnf install ansible-core

    The only other requirement is to install the Ansible collection dedicated to Quarkus:

    $ ansible-galaxy collection install middleware_automation.quarkus

    This is all you need to prepare the Ansible control machine (the name given to the machine executing Ansible).

    Generally, the control node is used to set up other systems that are designated under the name targets. For the purpose of this tutorial, and for simplicity's sake, we are going to utilize the same system for both the control node and our (only) target. This will make it easier to reproduce the content of this article on a single development machine.

    Note that you don’t need to set up any kind of Java development environment, because the Ansible collection will take care of that.

    The Ansible collection dedicated to Quarkus is a community project, and it’s not supported by Red Hat. However, both Quarkus and Ansible are Red Hat products and thus fully supported. The Quarkus collection might be supported at some point in the future, but is not as the time of the writing of this article.

    Inventory file

    Before we can execute Ansible, we need to provide to the tool an inventory of the targets. There are many ways to achieve that, but the simplest solution for a tutorial such as this one is to write up an inventory file of our own.

    As mentioned above, we are going to use the same host for both the controller and the target, so the inventory file has only one host. Here again, for simplicity's sake, this machine is going to be the localhost: 

    $ cat inventory
    [all]
    localhost ansible_connection=local

    Refer to the Ansible documentation for more information on Ansible inventory.

    Build and deploy the app with Ansible

    For this demonstration, we are going to utilize one of the sample applications provided as part of the Quarkus quick starts project. We will use Ansible to build and deploy the getting started application.

    All we need to provide to Ansible is the application name, repository URL, and the destination folder, where to deploy the application on the target. Because of the directory structure of the Quarkus quick start, containing several projects, we'll also need to specify the directory containing the source code:

    $ ansible-playbook -i inventory middleware_automation.quarkus.playbook \
                       -e app_name='optaplanner-quickstart' \
                       -e quarkus_app_source_folder='optaplanner-quickstart' \
                       -e quarkus_path_to_folder_to_deploy=/opt/optplanner \
                       -e quarkus_app_repo_url='https://github.com/quarkusio/quarkus-quickstarts.git'

    Below is the output of this command :

    PLAY [Build and deploy a Quarkus app using Ansible] ****************************
    
    TASK [Gathering Facts] *********************************************************
    
    ok: [localhost]
    
    TASK [Build the Quarkus from https://github.com/quarkusio/quarkus-quickstarts.git.] ***
    
    TASK [middleware_automation.quarkus.quarkus : Ensure required parameters are provided.] ***
    
    ok: [localhost]
    
    TASK [middleware_automation.quarkus.quarkus : Define path to mvnw script.] *****
    
    ok: [localhost]
    
    TASK [middleware_automation.quarkus.quarkus : Ensure that builder host localhost has appropriate JDK installed: java-17-openjdk] ***
    
    changed: [localhost]
    
    TASK [middleware_automation.quarkus.quarkus : Delete previous workdir (if requested).] ***
    
    ok: [localhost]
    
    TASK [middleware_automation.quarkus.quarkus : Ensure app workdir exists: /tmp/workdir] ***
    
    changed: [localhost]
    
    TASK [middleware_automation.quarkus.quarkus : Checkout the application source code.] ***
    
    changed: [localhost]
    
    TASK [middleware_automation.quarkus.quarkus : Build the App using Maven] *******
    
    ok: [localhost]
    
    TASK [middleware_automation.quarkus.quarkus : Display build application log] ***
    
    skipping: [localhost]
    
    TASK [Deploy Quarkus app on target.] *******************************************
    
    TASK [middleware_automation.quarkus.quarkus : Ensure required parameters are provided.] ***
    
    ok: [localhost]
    
    TASK [middleware_automation.quarkus.quarkus : Ensure requirements on target system are fullfilled.] ***
    
    included: /root/.ansible/collections/ansible_collections/middleware_automation/quarkus/roles/quarkus/tasks/deploy/prereqs.yml for localhost
    
    TASK [middleware_automation.quarkus.quarkus : Ensure required OpenJDK is installed on target.] ***
    
    skipping: [localhost]
    
    TASK [middleware_automation.quarkus.quarkus : Ensure Quarkus system group exists on target system] ***
    
    changed: [localhost]
    
    TASK [middleware_automation.quarkus.quarkus : Ensure Quarkus user exists on target system.] ***
    
    changed: [localhost]
    
    TASK [middleware_automation.quarkus.quarkus : Ensure deployement directory exits: /opt/optplanner.] ***
    
    changed: [localhost]
    
    TASK [middleware_automation.quarkus.quarkus : Set Quarkus app source dir (if not defined).] ***
    
    ok: [localhost]
    
    TASK [middleware_automation.quarkus.quarkus : Deploy application as a systemd service on target system.] ***
    
    included: /root/.ansible/collections/ansible_collections/middleware_automation/quarkus/roles/quarkus/tasks/deploy/service.yml for localhost
    
    TASK [middleware_automation.quarkus.quarkus : Deploy application from  to target system] ***
    
    ok: [localhost]
    
    TASK [middleware_automation.quarkus.quarkus : Deploy Systemd configuration for Quarkus app] ***
    
    changed: [localhost]
    
    TASK [middleware_automation.quarkus.quarkus : Perform daemon-reload to ensure the changes are picked up] ***
    
    ok: [localhost]
    
    TASK [middleware_automation.quarkus.quarkus : Ensure Quarkus app service is running.] ***
    
    changed: [localhost]
    
    TASK [middleware_automation.quarkus.quarkus : Ensure firewalld configuration is appropriate (if requested).] ***
    
    skipping: [localhost]
    
    PLAY RECAP *********************************************************************
    
    localhost              : ok=19   changed=8 unreachable=0 failed=0 skipped=3 rescued=0 ignored=0  

    As you can see, the Ansible collection for Quarkus does all the heavy lifting for us: its content takes care of checking out the source code from GitHub and builds the application. It also ensures the system used for this step has the required OpenJDK installed on the target machine.

    Once the application is successfully built, the collection takes care of the deployment. Here again, it checks that the appropriate OpenJDK is available on the target system. Then, it verifies that the required user and group exist on the target and if not, creates them. This is recommended mostly to be able to run the Quarkus application with a regular user, rather than with the root account.

    With those requirements in place, the jars produced during the build phase are copied over to the target, along with the required configuration for the application integration into systemd as a service. Any change to the systemd configuration requires reloading its daemon, which the collection ensures will happen whenever it is needed. With all of that in place, the collection starts the service itself.

    Validate the execution results 

    Let’s take a minute to verify that all went well and that the service is indeed running:

    # systemctl status optaplanner-quickstart.service
    ● optaplanner-quickstart.service - A Quarkus service named optaplanner-quickstart
       Loaded: loaded (/usr/lib/systemd/system/optaplanner-quickstart.service; enabled; vendor preset: disabled)
       Active: active (running) since Wed 2023-04-26 09:40:13 UTC; 3h 19min ago
     Main PID: 934 (java)
       CGroup: /system.slice/optaplanner-quickstart.service
            └─934 /usr/bin/java -jar /opt/optplanner/quarkus-run.jar
    
    Apr 26 09:40:13 be44b3acb1f3 systemd[1]: Started A Quarkus service named optaplanner-quickstart.
    Apr 26 09:40:14 be44b3acb1f3 java[934]: __  ____  __  _____   ___  __ ____  ______
    Apr 26 09:40:14 be44b3acb1f3 java[934]:  --/ __ \/ / / / _ | / _ \/ //_/ / / / __/
    Apr 26 09:40:14 be44b3acb1f3 java[934]:  -/ /_/ / /_/ / __ |/ , _/ ,< / /_/ /\ \
    Apr 26 09:40:14 be44b3acb1f3 java[934]: --\___\_\____/_/ |_/_/|_/_/|_|\____/___/
    Apr 26 09:40:14 be44b3acb1f3 java[934]: 2023-04-26 09:40:14,843 INFO  [io.quarkus] (main) optaplanner-quickstart 1.0.0-SNAPSHOT on JVM (powered by Quarkus 2.16.6.Final) started in 1.468s. Listening on: http://0.0.0.0:8080
    Apr 26 09:40:14 be44b3acb1f3 java[934]: 2023-04-26 09:40:14,848 INFO  [io.quarkus] (main) Profile prod activated.
    Apr 26 09:40:14 be44b3acb1f3 java[934]: 2023-04-26 09:40:14,848 INFO  [io.quarkus] (main) Installed features: [agroal, cdi, hibernate-orm, hibernate-orm-panache, hibernate-orm-rest-data-panache, jdbc-h2, narayana-jta, optaplanner, optaplanner-jackson, resteasy-reactive, resteasy-reactive-jackson, resteasy-reactive-links, smallrye-context-propagation, vertx, webjars-locator]
    

    Having the service running is certainly good, but it does not guarantee by itself that the application is available. To double-check, we can simply confirm the accessibility of the application by connecting to it:

    # curl -I http://localhost:8080/
    HTTP/1.1 200 OK
    accept-ranges: bytes
    content-length: 8533
    cache-control: public, immutable, max-age=86400
    last-modified: Wed, 26 Apr 2023 10:00:18 GMT
    date: Wed, 26 Apr 2023 13:00:19 GMT

    Writing up a playbook

    The default playbook provided with the Ansible collection for Quarkus is quite handy and allows you to bootstrap your automation with a single command. However, most likely, you’ll need to write your own playbook so you can add automation required around the deployment of your Quarkus app.

    Here is the content of the playbook provided with the collection that you can simply use as a base for your own:

    ---
    - name: "Build and deploy a Quarkus app using Ansible"
      hosts: all
      gather_facts: false
      vars:
        quarkus_app_repo_url: 'https://github.com/quarkusio/quarkus-quickstarts.git'
        app_name: optaplanner-quickstart'
        quarkus_app_source_folder: 'optaplanner-quickstart'
        quarkus_path_to_folder_to_deploy: '/opt/optaplanner'
          
      pre_tasks:
    
        - name: "Build the Quarkus from {{ quarkus_app_repo_url }}."
          ansible.builtin.include_role:
            name: quarkus
            tasks_from: build.yml
    
      tasks:
    
        - name: "Deploy Quarkus app on target."
          ansible.builtin.include_role:
            name: quarkus
            tasks_from: deploy.yml
    
    

    To run this playbook, you again use the ansible-playbook command, but providing the path to the playbook:

    $ ansible-playbook -i inventory playbook.yml

    Conclusion

    Thanks to the Ansible collection for Quarkus, the work needed to automate the deployment of a Quarkus application is minimal. The collection takes care of most of the heavy lifting and allows its user to focus on the automation needs specific to their application and business needs.

    Explore other Ansible tutorials on Red Hat Developer:

    • Update and upgrade JBoss EAP with Ansible
    • Automate your SSO with Ansible and Keycloak
    • Automate JBoss Web Server deployment with the Red Hat Certified Content Collection for JWS
    • Deploy Keycloak single sign-on with Ansible
    • Deploy Infinispan automatically with Ansible
    • Automate and deploy a JBoss EAP cluster with Ansible
    • Set up mod_cluster for Red Hat JBoss Web Server with Ansible
    Last updated: August 14, 2023

    Related Posts

    • Learn Quarkus faster in the Developer Sandbox for Red Hat OpenShift

    • 6 steps to install Ansible Automation Platform 2.3 on RHEL

    • Quarkus for Spring developers: Kubernetes-native design patterns

    • Quarkus Superheroes: Managed services save the day

    • Automate your SSO with Ansible and Keycloak

    Recent Posts

    • Every layer counts: Defense in depth for AI agents with Red Hat AI

    • Fun in the RUN instruction: Why container builds with distroless images can surprise you

    • Trusted software factory: Building trust in the agentic AI era

    • Build a zero trust AI pipeline with OpenShift and RHEL CVMs

    • Red Hat Hardened Images: Top 5 benefits for software developers

    What’s up next?

    Quarkus for Spring Developers

    Learn how to optimize Java for today’s compute and runtime demands with Quarkus. Quarkus for Spring Developers introduces Quarkus to Java developers, with a special eye for helping those familiar with Spring’s conventions make a quick and easy transition.

    Get the e-book
    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.