Skip to main content
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 Red Hat 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

    • Red Hat OpenShift AI
    • 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.

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

    • 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.

ConsoleDocsSupport Search
New For you

Recommended

We'll recommend resources you may like as you browse. Try these suggestions for now.

  • Product downloads
  • Cheat sheets
  • Red Hat Developer learning portal
  • Developer blog
  • E-books
  • Developer Sandbox
Log in

Get more with a Red Hat Developer account

  • Product downloads
  • Console access
  • Event registration
  • Training & trials
Explore more account benefitsLog in or register

A subscription may be required for some services.

Contact us

3 steps to secure network segmentation with Ansible and AWS

June 26, 2025
Alina Buzachis
Related topics:
AutomationDeveloper productivityDevOps
Related products:
Red Hat Ansible Automation Platform

    In our previous article, How to scale smarter with Ansible and amazon.aws 9.0.0, we explored key updates in the amazon.aws 9.0.0 Ansible collection and demonstrated how to automate cloud scaling in Amazon Web Services (AWS) environments.

    This article is the second in a three-part series exploring real-world use cases that showcase the power of these new capabilities. Today, we’ll focus on secure network segmentation—leveraging Red Hat Ansible Automation Platform to efficiently manage AWS Transit Gateways, Virtual Private Cloud (VPC) attachments, and Network Access Control Lists (ACLs) for centralized connectivity and robust security controls.

    Stay tuned for the final article, where we’ll cover multi-VPC connectivity. For now, let’s dive into automation strategies that help you build a secure and scalable network infrastructure with Ansible Automation Platform and AWS.

    Secure network segmentation

    As organizations adopt cloud-native architectures, maintaining seamless communication between multiple VPCs while enforcing strong security controls becomes critical.

    AWS Transit Gateways and Network ACLs enable this by simplifying network connections and providing robust traffic filtering. This use case explores how to set up a Transit Gateway to centralize VPC connectivity and implement Network ACLs to secure traffic within a VPC.

    The scenario starts by creating a Transit Gateway, which acts as a network hub to interconnect multiple VPCs. This centralization reduces complexity and improves network performance. Next, we attach a VPC to the Transit Gateway to enable communication between resources in different VPCs. To enhance security, we create a Network ACL for the VPC to manage inbound and outbound traffic at the subnet level. Network ACLs allow us to define rules that filter traffic based on IP addresses, ports, and protocols, providing an additional layer of protection. 

    This use case emphasizes the importance of balancing connectivity and security in cloud environments. We use the following modules:

    • ec2_transit_gateway: Manages EC2 Transit Gateways.

    • ec2_transit_gateway_info: Retrieves information about EC2 Transit Gateways in AWS.

    • ec2_transit_gateway_vpc_attachment: Manages EC2 Transit Gateway VPC attachments.

    • ec2_transit_gateway_vpc_attachment_info: Retrieves information about EC2 Transit Gateway VPC Attachments.

    • ec2_vpc_nacl: Manages Network ACLs.

    • ec2_vpc_nacl_info: Retrieves information about Network ACLs in an AWS VPC.

    3-step implementation guide

    Now that we've outlined the key automation modules for secure network segmentation, let's walk through the step-by-step implementation of a secure and scalable network infrastructure using Ansible. This guide will explain how to:

    1. Create a Transit Gateway to centralize VPC connectivity.
    2. Attach a VPC to the Transit Gateway to enable seamless inter-VPC communication.
    3. Configure a Network ACL to secure traffic at the subnet level.

    By following these steps, you ensure that your network remains highly secure, resilient, and scalable, without the need for manual intervention.

    Let’s break down the Ansible Playbook into these clear, actionable steps and see how each one streamlines the process of implementing secure network segmentation in AWS.

    1. Create a Transit Gateway

    The amazon.aws.ec2_transit_gateway module creates a Transit Gateway for interconnecting VPCs. A Transit Gateway acts as a central hub for VPC connections, simplifying routing and reducing the complexity of managing multiple point-to-point connections. We also use the amazon.aws.ec2_transit_gateway_info module to check for any existing gateways before creating a new one:

    ---
    - name: Secure Network Segmentation with Transit Gateways and Network ACLs
      hosts: localhost
      gather_facts: false
      tasks:
       - name: Check if any transit gateway exists using some filters before creating a new one
         amazon.aws.ec2_transit_gateway_info:
           filters:
             options.dns-support: enable
             options.vpn-ecmp-support: enable
         register: _result_transit_gateway_info
       - name: Create transit gateway
         amazon.aws.ec2_transit_gateway:
           state: present
           description: "Transit Gateway for inter-VPC communication"
         register: _result_transit_gateway
         when: _result_transit_gateway_info.transit_gateways | length == 0

    2. Attach a VPC to the Transit Gateway

    Next, we attach a VPC to the Transit Gateway so that resources in different VPCs can communicate seamlessly. The amazon.aws.ec2_transit_gateway_vpc_attachment module performs this task, while the corresponding info module helps retrieve and verify the attachment details:

       - name: Attach VPC to transit gateway
         amazon.aws.ec2_transit_gateway_vpc_attachment:
           state: present
           transit_gateway_id: "{{ _result_transit_gateway.transit_gateway.id }}"
           subnet_ids:
             - "subnet-12345678"
             - "subnet-87654321"
           dns_support: true
           ipv6_support: true
           appliance_mode_support: false
       - name: Retrieve VPC attachment details
         amazon.aws.ec2_transit_gateway_vpc_attachment_info:
           id: "{{ _result_transit_gateway.transit_gateway.id }}"

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

    [Partial log]
    …
    "attachments": [
            {
                "creation_time": "2025-01-20T09:54:58+00:00",
                "options": {
                    "appliance_mode_support": "disable",
                    "dns_support": "enable",
                    "ipv6_support": "enable",
                    "security_group_referencing_support": "enable"
                },
                "state": "available",
                "subnet_ids": [
                    "subnet-12345678”,
                     "subnet-87654321”,
                ],
                "tags": {},
                "transit_gateway_attachment_id": "tgw-attach-0c17c8a1bda4839a8",
                "transit_gateway_id": "tgw-0352dd6837d1d140f",
                "vpc_id": "vpc-0ef0a301a6b8a2f5c",
                "vpc_owner_id": "1234567891234"
            }
    ]

    3. Create a Network ACL

    Finally, we configure a Network ACL to enforce security policies at the subnet level. Using the amazon.aws.ec2_vpc_nacl module, we define rules to control both inbound and outbound traffic. We use the amazon.aws.ec2_vpc_nacl_info module to retrieve and verify the ACL configuration:

       - name: Configure network ACL for VPC
         amazon.aws.ec2_vpc_nacl:
           state: present
           vpc_id: "vpc-12345678"
           name: "secure-nacl"
           subnets:
             - "subnet-12345678"
             - "subnet-87654321"
           ingress:
             - [100, 'tcp', 'allow', '0.0.0.0/0', null, null, 22, 22]   # Allow SSH access on port 22
             - [200, 'tcp', 'allow', '0.0.0.0/0', null, null, 80, 80]   # Allow HTTP access on port 80
           egress:
             - [100, 'all', 'allow', '0.0.0.0/0', null, null, null, null]   # Allow all outbound traffic
           state: "present"
         register: _result_network_acl
       - name: Retrieve network ACL details
         amazon.aws.ec2_vpc_nacl_info:
           nacl_ids:
              - "{{ _result_network_acl.nacl_id }}"

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

    [Partial log]
    …
    "nacls": [
            {
                "egress": [
                    [
                        100,
                        "all",
                        "allow",
                        "0.0.0.0/0",
                        null,
                        null,
                        0,
                        65535
                    ]
                ],
                "ingress": [
                    [
                        100,
                        "tcp",
                        "allow",
                        "0.0.0.0/0",
                        null,
                        null,
                        22,
                        22
                    ],
                    [
                        200,
                        "tcp",
                        "allow",
                        "0.0.0.0/0",
                        null,
                        null,
                        80,
                        80
                    ],
                ],
                "is_default": false,
                "nacl_id": "acl-002b90246b9e3009d",
                "owner_id": "721066863947",
                "subnets": [
                    "subnet-12345678”,
                    "subnet-87654321"            ],
                "tags": {
                    "Name": "secure-nacl"
                },
                "vpc_id": "vpc-12345678"
            }
    ]

    What's next?

    In this article, we demonstrated how the latest new modules in the amazon.aws 9.0.0 collection empower you to automate secure network segmentation in AWS. By walking through a practical use case, from creating a Transit Gateway and attaching a VPC to configuring a Network ACL, we showcased how these new modules simplify the process of balancing connectivity with robust security controls. This automation reduces manual intervention while ensuring your network remains secure, resilient, and scalable.

    In the final article of our series, we’ll explore multi-VPC connectivity, another critical component 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

    • Generate Ansible Playbooks using natural language prompts

    • Customizing an OpenShift Ansible Playbook Bundle

    • How Ansible Automation task scheduling improves productivity

    • How to scale smarter with Ansible and amazon.aws 9.0.0

    • Create AWS resources with Kubernetes and Operators

    Recent Posts

    • A day in the life of an NVIDIA H100 on Red Hat OpenShift 5

    • Migrate BuildConfigs to builds for Red Hat OpenShift with one plug-in install

    • Run Red Hat Enterprise Linux CoreOS on NVIDIA BlueField DPUs

    • Agent harness engineering: Separating model capabilities from enforcement

    • What's new for developers in Red Hat Enterprise Linux 10.3 and 9.9

    What’s up next?

    In this learning path, discover Ansible Content Collections through practical examples that explain their advantages, and then create and use them in your Ansible automation.

    Start the activity
    Red Hat Developers logo

    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
    Ask AI