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

How to create an EC2 instance in AWS using Ansible automation

June 5, 2023
Deepankar Jain
Related topics:
Automation and management
Related products:
Red Hat Ansible Automation PlatformRed Hat Ansible Automation Platform via AWS

Share:

    In our previous article, we explored how to use the Red Hat Ansible Automation Platform CLI to create an Elastic Compute Cloud (EC2) in Amazon Web Services (AWS). This time, we will take things a step further and leverage the power of the Ansible Automation Platform to automate the process. Ansible Automation Platform is a powerful tool that enables you to manage your infrastructure more efficiently with less manual intervention.

    Follow the series:

    Part 1: How to create an EC2 instance on AWS using Ansible CLI

    Part 2: How to create an EC2 instance in AWS using Ansible Automation

    Part 3: How to create EC2 instance on AWS using Ansible workflow

    By using Ansible Automation Platform, we can create a streamlined process for deploying EC2s in AWS, reducing errors and saving time. In this article, we will dive into the details of how to use Ansible Automation Platform to create instances in AWS and explore the benefits of using this powerful automation tool.

    How to create credentials

    Follow these steps to create your credentials as referenced in Figure 1:

    • Navigate to the Credentials Tab under Resources in Ansible Automation Platform.
    • Select Amazon Web Services under Credential type.
    • Add your access key and secret key, then save it.
      A screenshot of the Ansible create AWS credentials page.
      Figure 1: The Ansible create credentials page.

    Creating and configuring the project

    Follow these steps to create and configure your project:

    • Install Ansible Automation Platform by following the instructions in the article How to install Red Hat Ansible Automation Platform on RHEL 9.
    • Log in to Ansible Automation Platform portal in the browser.
    • Navigate to the Projects tab under Resources in the left pane.
    • Click on the Add button to create a new project.
    • Enter a name for the project and choose Git as the source control type with the URL https://github.com/redhat-developer-demos/ansible-automation-platform-cloud-solutions in the Source Control URL field. (If you're interested in checking out the Ansible playbooks, you can find them on GitHub.)
    • Save the changes and wait for the operation to complete successfully, as shown in Figure 2.
    A screenshot of the form for configuring the project source control in Ansible.
    Figure 2: Configuring the project source control.

    Creating and configuring the job template

    Follow these steps to create and configure the job template:

    • Go to the Templates tab under Resources in the left pane.
    • Click on the Add button and select Job template from the options.
    • Enter a name for the job you want to create.
    • In the Inventory section, select the Demo-Inventory or Default inventory.
    • In the Project section, click on the project name you previously created and select the AWS/create_ec2instance.yml file.

    Configuring the variables and execution environment

    • Click on the Variables section.
    • Add the variables as follows:
    
    ---
    
    region: ap-south-1
    
    instance_type: t3.micro
    
    ami: ami-0f9d9a251c1a44858
    
    key_name: ansible-demo
    
    vpc_name: ansible-vpc-test
    
    cidr_block: "10.10.0.0/16"
    
    cidr: "10.10.0.0/24"
    • Select the credentials you previously created under the selected category, as shown in Figure 3.
    A screenshot of the form for AWS credentials secure authentication.
    Figure 3: Selecting pre-configured AWS credentials for secure authentication.
    • Select the default execution environment, as shown in Figure 4. 
    A screenshot of where to Select the default execution environment in Ansible.
    Figure 4: Selecting the default execution environment.
    • Save your changes by clicking the Save button.
    • Finally, launch the job by clicking on the Launch button.
    • Once the job is launched using Ansible Automation Platform, the system will generate an output that should be similar to Figure 5.
    A screenshot of the output from the job in Ansible.
    Figure 5: Output from the job.

    The output will display the status of the job and the progress of the instance creation process, as shown in Figure 6.

    A screenshot of the EC2 instance created in AWS.
    Figure 6: Showing the EC2 Instance in AWS.

    What’s next?

    In this article, we explored how to use Ansible Automation Platform to create an EC2 instance in Amazon Web Services. We demonstrated how Ansible Automation Platform can streamline the process of deploying EC2s in AWS, making it more efficient and less error-prone. By using the power of automation, we can save time and free up resources to focus on other important tasks.

    To explore more of what Ansible Automation Platform has to offer, visit the official website to download and get started. Additionally, there are various e-books available to help you explore the capabilities of Ansible Automation Platform such as:

    • Automation at the edge
    • Choosing an automation tool
    • An IT executive's guide to automation

    There is also a cheat sheet for WiFi automation with Ansible and SD that provides a quick reference for network automation tasks.

    In the final article of this series, we go even further by exploring how to simplify the process of creating an EC2 instance in AWS using workflow templates to optimize infrastructure management. Workflow templates standardize the process of creating instances and reduce the amount of manual intervention required. 

    Last updated: January 11, 2024

    Related Posts

    • How we automate everything at Red Hat Open Innovation Labs

    • How to install Red Hat Ansible Automation Platform on RHEL 9

    • How to install VMs and Ansible Automation Platform on Mac M1

    • Using OpenShift with AWS Services and Features

    Recent Posts

    • Cloud bursting with confidential containers on OpenShift

    • Reach native speed with MacOS llama.cpp container inference

    • A deep dive into Apache Kafka's KRaft protocol

    • Staying ahead of artificial intelligence threats

    • Strengthen privacy and security with encrypted DNS in RHEL

    What’s up next?

    Share Image

    This cheat sheet gets you started using Ansible to automate tasks on Cisco Meraki, an enterprise-cloud managed networking solution for managing access points, security appliances, L2 and L3 switches, and more.

    Get the cheat sheet
    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