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

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

    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

    • Protect data offloaded to GPU-accelerated environments with OpenShift sandboxed containers

    • Case study: Measuring energy efficiency on the x64 platform

    • How to prevent AI inference stack silent failures

    • Preventing GPU waste: A guide to JIT checkpointing with Kubeflow Trainer on OpenShift AI

    • How to manage TLS certificates used by OpenShift GitOps operator

    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

    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.