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

How to deploy applications using Ansible Automation Platform

July 20, 2023
Tathagata Paul Himanshu Yadav
Related topics:
Automation and managementContainersLinux
Related products:
Red Hat Ansible Automation PlatformRed Hat Enterprise Linux

Share:

    In this article, we will demonstrate how to streamline the application deployment process on a Red Hat Enterprise Linux machine using Red Hat Ansible Automation Platform.

    Prerequisites

    1. Two local VM’s configured with SSH connectivity.
    2. Bridged networking enabled for the VMs.
    3. Ansible Automation Platform installed on the host VM.

    Our VMs are named vm1-host and vm2 respectively. Edit the /etc/hosts file on vm1-host to include the other VM as a device on the network. You can find its IP by using the command ip -a and then checking the inet address. In my case, it was the following address:

    192.168.17.4 vm2

    You can try the following command to ping the other VM to check if the connection works.

    ping vm2 

    After that, enable SSH and copy them to all the VMs using the following commands:

    ssh-keygen
    ssh-copy-id vm2

    Now, once SSH is enabled and the machine is reachable from our host, we can start writing our inventory and playbook file. You can copy the inventory and playbook file from my Github.

    The playbook file looks like this:

    ---
    - hosts: webstack
      become: true
      tasks:
      - name: Installing podman
        package:
          name: "podman"
          state: present
    
      - name: Pull an image
        containers.podman.podman_image:
          name: docker.io/httpd
    
      - name: run httpd container
        containers.podman.podman_container:
          name: webserver
          image: httpd
          state: started
          detach: true
          expose:
            - 80
          ports:
            - 8080:80
    

    Our main tasks are as follows:

    • Installing Podman on the webstack servers.
    • Pulling a httpd image using the containers.podman.podman_image module.
    • Running the httpd image in Podman and exposing it on port 8080 on localhost.

    Upload these files to some source control (GitHub or GitLab) so that we can access them in our project later.

    Also, running the containers.podman.podman_image module requires us to have it installed in our execution environment. First we need to have a Red Hat registry service account. Login to your registry account using podman as follows:

    podman login registry.redhat.io
    Username: {REGISTRY-SERVICE-ACCOUNT-USERNAME} 
    Password: {REGISTRY-SERVICE-ACCOUNT-PASSWORD}   
    Login Succeeded!

    Then, we must write a container file to help build our execution environment that has this module:

    FROM FROM registry.redhat.io/ansible-automation-platform-23/ee-minimal-rhel8:latest
    RUN ansible-galaxy collection install containers.podman
    COPY hosts /etc/hosts
    

    To build an image using podman:

    podman build -t <image-name>.

    The image should be pushed into the container image registry such as quay.io. Log in to the private container image registry using the command podman login before pushing.

    podman push <image-name>

    Make sure Ansible Automation Platform is installed on your system. You can follow the instructions in the article, 6 steps to install Ansible Automation Platform 2.3 on RHEL. For now, we will be installing it on the localhost because our entire network is on our machine itself in VMs. For production environments, changes might be needed in the installation inventory file.

    Navigate to https://localhost and log in to the dashboard.

    Create a new project

    A project is a collection of Ansible Playbooks that perform a certain set of automated tasks. Our project will contain our single playbook which will download and deploy a httpd server on a VM.

    Steps to create a new project:

    1. Head over to the Projects tab.
    2. Click on the Add option and then select a name for the project and select the default organization.
    3. Save the project.
    4. Figure 1 shows the project details page.
    A screenshot of the project details in Ansible.
    Figure 1: The project details page.
    ​​​​​

    Steps to create an inventory:

    1. Create an inventory from the inventories tab and add a group named webstack.
    2. Navigate to the created group.
    3. Click on the Related Groups tab and add the second group webservers.
    4. Figure 2 shows the inventory details page.
    A screenshot of the inventory details page in Ansible.
    Figure 2: The inventory details page.

    Head back to the inventory edit page and navigate to the Hosts tab and add a host with the name as the IP address of vm2 (Figure 3).

    A screenshot of the hosts page in Ansible.
    Figure 3: The Hosts page.

    Steps to add a credential for the VMs:

    1. Navigate to the Credential tab and add a credential with type Machine, username and password as that of vm2 and private key as copied over from vm1-host’s file: ~/.ssh/id_rsa.
    2. Fill the Privilege Escalation password with the password for vm2 which will run the commands as sudo on vm2.
    3. Figure 4 shows the credentials details page.
    A screenshot of the credentials details page in Ansible.
    Figure 4: The credentials details page.

    Next we add an execution environment from the left pane. We set the image URL as the one from the private registry we uploaded the EE image to and set Pull policy to Always. Figure 5 shows the execution environment details page.

    The execution environment details page in Ansible.
    Figure 5: The execution environment details page.

    Steps to create a template:

    1. Head over to the Templates tab and create a new template.
    2. Add the project we created, and the playbook from our GitHub, or any other source control repository we uploaded the playbook to.
    3. Add the inventory, credentials and the execution environment fields as necessary.
    4. Figure 6 shows the templates details page.
    The templates details page in Ansible.
    Figure 6: The templates details page.

    We launch our template to see it running. It might take a while to pull the execution environment image. After completion, we can see that the job was executed successfully in the Jobs tab.

    Head over to the vm2 machine and navigate to https://localhost:8080 to see the page that shows that it works.

    Continue your automation journey with Ansible

    You can get started with the Ansible Automation Platform by exploring interactive labs at Red Hat Developer. Check out Red Hat’s hands-on labs for all skill levels to learn more. The labs include a wide range of topics such as useful Linux commands, Install software using package managers, and Deploying containers using container tools [podman]. Try these labs to see your favourite products in action.

    Last updated: September 21, 2023

    Related Posts

    • How to use OpenShift GitOps to deploy applications

    • 5 examples of security automation with Ansible

    • Using Ansible to automate Google Cloud Platform

    Recent Posts

    • Exploring Llama Stack with Python: Tool calling and agents

    • Enhance data security in OpenShift Data Foundation

    • AI meets containers: My first step into Podman AI Lab

    • Live migrating VMs with OpenShift Virtualization

    • Storage considerations for OpenShift Virtualization

    What’s up next?

    Why automate? Which tool do I use? This e-book dives into various automation options, how they work, what to automate, and the benefits of each tool.

    Download 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