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 scale smarter with Ansible and amazon.aws 9.0.0

Strategies for effortless cloud scaling

March 25, 2025
Alina Buzachis
Related topics:
Automation and managementDeveloper ProductivityDevOpsOpen source
Related products:
Red Hat Ansible Automation Platform

Share:

    In our previous article, What's New: Cloud Automation with amazon.aws 9.0.0, we introduced the latest release of the Red Hat Ansible Certified Content Collection for Amazon Web Services (AWS). We covered key updates, new features, and recently supported modules designed to simplify cloud automation.

    This article kicks off a three-part series exploring real-world use cases that showcase the power of these new capabilities. In this installment, we’ll focus on automating infrastructure scaling, leveraging Red Hat Ansible Automation Platform to efficiently manage Auto Scaling Groups (ASGs), Elastic Compute Cloud (EC2) launch templates, and instance refresh processes for seamless scaling and configuration consistency.

    Stay tuned for the next two posts, where we’ll cover secure network segmentation and multi-virtual private cloud (VPC) connectivity—two critical aspects of modern cloud architectures. For now, let’s dive into automation strategies that help you scale smarter with Ansible Automation Platform and AWS.

    Automated infrastructure scaling and refresh

    In dynamic cloud environments, applications must be able to efficiently scale in response to fluctuating workloads. Auto Scaling Groups provide this flexibility by automatically adjusting the number of EC2 instances based on demand. However, ensuring that all instances in the ASG are consistently updated with the latest configurations can be a challenge, especially when changes need to be applied without causing service disruption.

    This use case highlights the power of automation in managing a scalable, resilient, and cost-optimized infrastructure. By minimizing manual intervention and downtime, it ensures the infrastructure can handle fluctuating workloads while staying up to date with the latest configurations and maintaining high availability.

    This use case focuses on leveraging the new modules shown in the following table.

    Module

    Description

    ec2_launch_template

    Manage EC2 launch templates.

    ec2_launch_template_info

    Retrieve information about EC2 launch templates.

    autoscaling_group

    Manage AWS ASGs.

    autoscaling_instance

    Manage instances associated with AWS Auto Scaling Groups (ASGs).

    autoscaling_instance_info

    Retrieve information about  instances associated with ASGs.

    ec2_placement_group

    Manage EC2 Placement Groups.

    ec2_placement_group_info

    List EC2 Placement Group(s) details.

    autoscaling_instance_refresh

    Start or cancel an EC2 ASG instance refresh in AWS.

    autoscaling_instance_refresh_info

    Retrieve information about EC2 ASG instance refreshes.

    5-step guide for implementation

    Now that we've outlined the key automation modules, let's walk through the step-by-step implementation of an automated, scalable, and resilient infrastructure using Ansible Automation Platform.

    This guide will demonstrate how to:

    1. Create an EC2 launch template for consistent instance deployment.
    2. Set up an ASG to dynamically adjust capacity.
    3. Optimize instance distribution with an EC2 Placement Group.
    4. Attach an existing EC2 Instance to the ASG.
    5. Perform a rolling instance refresh to update configurations seamlessly.

    By following these steps, we ensure that our infrastructure remains highly available, cost-optimized, and always up to date without manual intervention.

    Let’s break down an Ansible Playbook into several steps, and learn how each one assists in automating and streamlining the use case scenario I described. 

    Step 1: Create an EC2 launch template

    An EC2 launch template serves as a blueprint for provisioning EC2 instances, ensuring that all instances within an ASG share consistent configurations. It encapsulates key settings such as AMI IDs, instance types, security groups, and key pairs. The amazon.aws.ec2_launch_template module creates a launch template defining instance configurations. 

    Using amazon.aws.ec2_launch_template_info, you can verify that the launch template is correctly configured as follows:

    ---
    - name: Automate Autoscaling and Placement
      hosts: localhost
      tasks:
        - name: Create an EC2 launch template
          amazon.aws.ec2_launch_template:
            state: present
            name: "my-launch-template"
            image_id: "ami-1234567890abcdef0"
            instance_type: t3.micro
            key_name: "my-key-pair"
            tags:
              Environment: Production
          register: _result_launch_template
        - name: Retrieve details about the launch template
          amazon.aws.ec2_launch_template_info:
            filters:
              launch-template-name: "my-launch-template"
          register: _result_launch_template_info

    You can see the logs of the amazon.aws.ec2_launch_template_info module that confirm successful creation and retrieval of the launch template:

    [Partial log]
    …
    "launch_templates": [
            {
                "create_time": "2025-01-20T11:22:45+00:00",
                "created_by": "arn:aws:iam::123456789101:user/abuzachis",
                "default_version_number": 1,
                "latest_version_number": 1,
                "launch_template_id": "lt-06454f169fc012457",
                "launch_template_name": "my-launch-template",
                "tags": {
                    "Environment": "Production"
                },
                "versions": [
                    {
                        "create_time": "2025-01-20T11:22:45+00:00",
                        "created_by": "arn:aws:iam::123456789101:user/abuzachis",
                        "default_version": true,
                        "launch_template_data": {
                            "image_id": "ami-1234567890abcdef0",
                            "instance_type": "c4.large"
                        },
                        "launch_template_id": "lt-06454f169fc012457",
                        "launch_template_name": "my-launch-template",
                        "version_number": 1
                    }
                ]
            }
    ]

    Step 2: Create an Auto Scaling Group

    The amazon.aws.autoscaling_group module creates an ASG that ensures dynamic scalability by adjusting the number of instances based on demand. The ASG uses the launch template to manage the lifecycle of EC2 instances, maintaining availability and optimizing costs. It ensures the infrastructure can handle variable workloads without manual intervention. You can define the minimum, maximum, and desired capacity of the autoscaling group, ensuring it can adjust based on load. Tags are applied for organizational purposes, and the ASG spans across multiple availability zones to ensure high availability.

       - name: Create an ASG
         amazon.aws.autoscaling_group:
           state: present
           name: "my-asg"
           launch_template:
             launch_template_name: "{{ launch_template_info.name }}"
             version: "{{ launch_template_info.latest_version_number }}"
           min_size: 1
           max_size: 3
           desired_capacity: 2
           availability_zones:
             - "us-east-1a"
             - "us-east-1b"
           tags:
             - environment: production
               propagate_at_launch: true
         register: _result_autoscaling_group_info

    Step 3: Create an EC2 placement group

    The amazon.aws.ec2_placement_group module helps optimize the physical placement of your EC2 instances within the AWS infrastructure. Placement groups can improve network performance by grouping instances closer together, or enhance resilience by spreading instances across hardware. 

    In this example, a spread strategy is used, which places instances across different hardware. This is essential for ensuring high resilience and availability. In the following output, the amazon.aws.ec2_placement_group_info module fetches details about the placement group to verify that the group is created and configured as intended:

       - name: Create an EC2 placement group
         amazon.aws.ec2_placement_group:
           name: "my-placement-group"
           strategy: spread
           state: present
       - name: Retrieve information about the placement group
         amazon.aws.ec2_placement_group_info:
           names:
             - "my-placement-group"

    The following logs of the amazon.aws.ec2_placement_group_info module verify the group's configuration:

    [Partial log]
    …
    "placement_groups": [
            {
                "name": "my-placement-group",
                "state": "available",
                "strategy": "spread",
                "tags": {}
            }
    ]

    Step 4: Attach an instance to the ASG

    The amazon.aws.autoscaling_instance module attaches an existing EC2 instance to the ASG, making it part of the scaling group. This ensures that manually launched or external instances can become part of the ASG, optimizing resource utilization and enabling them to benefit from ASG management features like health checks and scaling. 

    Here, the amazon.aws.autoscaling_instance_info module retrieves information about the instances currently associated with the ASG:

       - name: Attach an external EC2 instance to the ASG
         amazon.aws.autoscaling_instance:
           group_name: "my-asg"
           state: present
           instance_ids:
             - "i-0abc12345d6789xyz"
           wait: true
        register: _result_attach_instance
       - name: Describe instances associated with ASG
         amazon.aws.autoscaling_instance_info:
           group_name: "my-asg"

    The following is a sample partial log output from the amazon.aws.austocaling_info module:

    [Partial log]
    …
    "auto_scaling_instances": [
            {
                "auto_scaling_group_name": "my-asg",
                "availability_zone": "us-east-1a",
                "health_status": "HEALTHY",
                "instance_id": "i-0762ce203680af6b2",
                "instance_type": "t3.micro",
                "launch_template": {
                    "launch_template_id": "lt-06454f169fc012457",
                    "launch_template_name": "my-launch-template",
                    "version": "1"
                },
                "lifecycle_state": "InService",
                "protected_from_scale_in": false
            }
    ]

    Step 5: Perform an instance refresh

    The amazon.aws.autoscaling_instance_refresh initiates a rolling refresh of instances in the ASG, updating them based on the latest launch template. Instance refresh updates the infrastructure without manual intervention, ensuring all instances meet the latest configurations. It ensures at least 50% of instances are healthy during the refresh and waits 300 seconds for new instances to initialize before proceeding. 

    The amazon.aws.autoscaling_instance_refresh_info module retrieves the status of the instance refresh process:

       - name: Perform an instance refresh to apply new launch template configuration
         amazon.aws.autoscaling_instance_refresh:
           name: "my-asg"
           state: started
           preferences:
             min_healthy_percentage: 50
             instance_warmup: 300
         register: _result_instance_refresh
       - name: Check the status of the instance refresh
         amazon.aws.autoscaling_instance_refresh_info:
           name: "my-asg"

    Here is a sample partial log from the amazon.aws.austocaling_instance_info module:

    [Partial log]
    …
    "instance_refreshes": [
            {
                "auto_scaling_group_name": "my-asg",
                "instance_refresh_id": "18462ba8-bfc7-443d-84fa-5821627f714d",
                "instances_to_update": 1,
                "percentage_complete": 0,
                "preferences": {
                    "alarm_specification": {},
                    "auto_rollback": false,
                    "instance_warmup": 300,
                    "min_healthy_percentage": 50,
                    "skip_matching": false
                },
                "start_time": "2025-01-20T09:45:39+00:00",
                "status": "Cancelling",
                "status_reason": "Replacing instances before cancelling."
            },
    ]

    What's next?

    In this article, we showcased how the latest features in the amazon.aws 9.0.0 collection enable you to automate intricate scaling operations within dynamic cloud environments. We walked through a practical use case, from creating an EC2 launch template to performing a rolling instance refresh. We also highlighted how these new modules streamline the management of ASGs, placement groups, and instance configurations. This automation not only reduces the need for manual intervention but also ensures that your infrastructure remains resilient, cost-optimized, and consistently up to date.

    Stay tuned for the next two articles in our series, where we’ll explore secure network segmentation and multi-VPC connectivity, the essential components for modern, secure cloud architectures.

    Looking to get started with Red Hat Ansible Automation Platform for Amazon Web Services?

    • Check out the Amazon Web Services Collection.
    • Try out our hands-on Interactive Labs.
    • Read the e-book Using automation to get the most from your public cloud.

    Learn more:

    • For further reading and information, visit the other articles related to Ansible Automation Platform.
    • Check out Red Hat Summit 2025.
    • Watch the YouTube playlist for everything about Ansible Collections.
    • If you're new to Ansible automation, check out our getting started guide on developers.redhat.com.

    Related Posts

    • How to deploy applications using Ansible Automation Platform

    • How Ansible Automation task scheduling improves productivity

    • How to create an EC2 instance in AWS using Ansible CLI

    • How to create an EC2 instance in AWS using Ansible workflow

    • The benefits of deploying Ansible Automation Platform on AWS

    Recent Posts

    • Integrate vLLM inference on macOS/iOS with Llama Stack APIs

    • Optimize model serving at the edge with RawDeployment mode

    • Introducing Red Hat build of Cryostat 4.0

    • How we improved AI inference on macOS Podman containers

    • How OpenShift Virtualization supports VM live migration

    What’s up next?

    Discover the basics of creating Ansible playbooks using practical examples, including key components such as plays, tasks, modules, and more in this learning path.

    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