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

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

    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

Simplify multi-VPC connectivity with amazon.aws 9.0.0

July 2, 2025
Alina Buzachis
Related topics:
Automation and managementDeveloper productivitySecurity
Related products:
Red Hat Ansible Automation Platform

    In our previous articles, How to scale smarter with Ansible and amazon.aws 9.0.0 and 3 steps to secure network segmentation with Ansible Automation Platform and AWS, we explored key updates in the amazon.aws 9.0.0 Ansible collection. We have demonstrated how to automate cloud scaling and how to implement strong security and network segmentation in Amazon Web Services (AWS) environments. 

    In this final article of our three-part series, we will focus on multi-Virtual Private Cloud (VPC) connectivity—a critical component for modern cloud architectures. As organizations expand their cloud environments, they often operate multiple VPCs to isolate workloads, improve security, and optimize resource management across regions. Ensuring secure and efficient communication between these VPCs, as well as with on-premise networks, is a challenge that requires a robust, automated solution.

    This article will demonstrate how to automate multi-VPC connectivity using VPC peering and virtual private network (VPN) gateways, which are critical components for building scalable, secure cloud architectures.

    How to secure multi-VPC connectivity

    Many organizations operate multiple VPCs in order to separate workloads, enhance security, or manage resources across different regions. These environments often require secure communication between VPCs and with on-premise networks. This use case demonstrates how to establish secure multi-VPC connectivity using peering, VPN gateways, and egress-only internet gateways for IPv6 traffic.

    First, we create a VPC peering connection to enable private communication between two VPCs. VPC peering is a cost-effective way to connect resources without exposing them to the public internet. 

    Next, we set up a VPN gateway for one of the VPCs to establish secure communication with an on-premise data center. This step is essential for hybrid cloud setups where sensitive data must be transmitted securely between the cloud and on-premise environments. 

    Finally, we configure an egress-only internet gateway for IPv6 traffic within the VPC. This gateway allows instances to initiate outbound internet connections while blocking inbound traffic, enhancing security for IPv6-enabled applications. Retrieving the gateway’s details confirms that it is ready to manage outbound IPv6 traffic.

    This use case showcases how to create secure and efficient multi-VPC and hybrid cloud architectures involving the following modules:

    • ec2_vpc_peering: Creates, deletes, accepts, and rejects VPC peering connections between two VPCs.

    • ec2_vpc_peering_info: Retrieves information about AWS VPC peerings.

    • ec2_vpc_vpn: Manages EC2 VPN connections.

    • ec2_vpc_vpn_info: Retrieves information about EC2 VPN connections.

    • ec2_vpc_egress_igw: Manages AWS VPC egress-only internet gateways.

    • ec2_vpc_egress_igw_info: Retrieves information about AWS VPC egress-only internet gateways.

    3-step implementation guide 

    Now that we’ve outlined the key automation modules involved in multi-VPC connectivity with peering and VPN gateways, let’s walk through the implementation of an automated, scalable, and resilient infrastructure using Ansible Automation Platform. 

    This guide will explain how to:

    1. Create a VPC peering connection to enable private communication between multiple VPCs.
    2. Set Up a VPN connection to securely link the cloud environment with an on-premise network.
    3. Configure an egress-only internet gateway for secure outbound IPv6 traffic.

    By following these steps, we will ensure that our infrastructure remains highly available, cost-optimized, and secure, while automating the process of establishing connectivity between VPCs and on-premise networks.

    We'll break down the Ansible playbook into steps and demonstrate how each task automates and streamlines the multi-VPC connectivity setup.

    1. Create VPC peering connection

    The first step is to establish private communication between two VPCs using a VPC peering connection. This allows the VPCs to exchange traffic securely without the need for a public IP or internet exposure. The amazon.aws.ec2_vpc_peering module creates a peering connection between two VPCs and accepts the peering request to enable communication between the VPCs. The amazon.aws.ec2_vpc_peering_info module retrieves information about the VPC peering connections:

    ---
    - name: Multi-VPC Connectivity with Peering and VPN Gateways
      hosts: localhost
      gather_facts: false
      tasks:
       - name: Create an EC2 VPC peering connection request
         amazon.aws.ec2_vpc_peering:
           state: present
           vpc_id: "vpc-12345678"
           peer_vpc_id: "vpc-87654321"
         register: _result_vpc_peering
       - name: Get all the EC2 VPC peering connections with specific filters
         amazon.aws.ec2_vpc_peering_info:
           filters:
             status-code: ["pending-acceptance"]
         register: _result_vpc_peering_info
       - name: Accept the EC2 VPC peering request
         amazon.aws.ec2_vpc_peering:
           peering_id: '{{ _result_vpc_peering_info.pending_vpc_peers.vpc_peering_connections[0].vpc_peering_connection_id }}'
           state: "accept"
           wait: true

    2. Create VPN connection 

    The amazon.aws.ec2_vpc_vpn module sets up a VPN connection using the customer gateway (on-premise device) and virtual private gateway (in the VPC). This establishes a secure communication channel between the VPC and an on-premise network, which is critical for hybrid cloud scenarios where sensitive data must be transferred securely between the cloud and the data center. The community.aws.ec2_customer_gateway module allows you to manage customer gateways in AWS. Customer gateways are used in VPN connections between an AWS Virtual Private Gateway (VPG) or a transit gateway and your on-premise network. The amazon.aws.ec2_vpc_vpn_info module retrieves information about the VPN connection:

       - name: Create VPN connection
         amazon.aws.ec2_vpc_vpn:
           state: present
           customer_gateway_id: "cgw-abc123"  # The ID of the customer gateway (on-premises device)
           vpn_gateway_id: "vgw-xyz789"  # The ID of the virtual private gateway in the VPC
           static_only: false  # Indicating that BGP (dynamic routing) is used, not static routing
           tunnel_options:
             - TunnelInsideCidr: "169.254.10.0/30"  # Internal CIDR range for the VPN tunnel
               PreSharedKey: "myPreSharedKey"  # Pre-shared key for authentication
        register: _vpn_connection
       - name: Retrieve VPN connection information
         amazon.aws.ec2_vpc_vpn_info:
           filters:
             vpn-gateway-id: "{{ _vpn_connection.vpn_connection_id }}"

    The following are the logs of the amazon.aws.ec2_vpc_vpn_info module: 

    [Partial log]
    …
    "vpn_connections": [
            {
                "category": "VPN",
                "customer_gateway_configuration": "<?xml version=\"1.0\" encoding=\"UTF-8\”?>\n …\n”,
                "customer_gateway_id": "cgw-abc123",
                "gateway_association_state": "associated",
                "options": {
                    "enable_acceleration": false,
                    "local_ipv4_network_cidr": "0.0.0.0/0",
                    "outside_ip_address_type": "PublicIpv4",
                    "remote_ipv4_network_cidr": "0.0.0.0/0",
                    "static_routes_only": false,
                    "tunnel_inside_ip_version": "ipv4",
                    "tunnel_options": [
                        {
                            "log_options": {
                                "cloud_watch_log_options": {
                                    "log_enabled": false
                                }
                            },
                            "outside_ip_address": "3.229.0.8",
                            "pre_shared_key": "myPreSharedKey",
                            "tunnel_inside_cidr": "169.254.10.0/30"
                        },
                        {
                            "log_options": {
                                "cloud_watch_log_options": {
                                    "log_enabled": false
                                }
                            },
                            "outside_ip_address": "184.72.102.191",
                            "pre_shared_key": "2hKkGhWeDD03dxs6332EEV7gwo.CeSaJ",
                            "tunnel_inside_cidr": "169.254.193.20/30"
                        }
                    ]
                },
                "routes": [],
                "state": "available",
                "tags": {},
                "type": "ipsec.1",
                "vgw_telemetry": [
                    {
                        "accepted_route_count": 0,
                        "last_status_change": "2025-01-20T10:56:37+00:00",
                        "outside_ip_address": "3.229.0.8",
                        "status": "DOWN",
                        "status_message": "IPSEC IS DOWN"
                    },
                    {
                        "accepted_route_count": 0,
                        "last_status_change": "2025-01-20T10:56:22+00:00",
                        "outside_ip_address": "184.72.102.191",
                        "status": "DOWN",
                        "status_message": "IPSEC IS DOWN"
                    }
                ],
                "vpn_connection_id": "vpn-07934309550c3a585",
                "vpn_gateway_id": "vgw-xyz789"
            }
    ]

    3. Set up egress-only internet gateway for IPv6

    The amazon.aws.ec2_vpc_egress_igw module configures an egress-only gateway. This gateway is used to manage outbound IPv6 traffic from the VPC to the internet while blocking any inbound IPv6 traffic. This is critical when instances in your VPC need to access the internet (e.g., software updates, accessing public services, etc.) but you don’t want to expose them to external inbound connections over IPv6. The amazon.aws.ec2_vpc_egress_igw_info module retrieves information about the egress-only internet gateway:

       - name: Set up egress-only internet gateway for IPv6
         amazon.aws.ec2_vpc_egress_igw:
           vpc_id: "vpc-12345678"
         register: _egress_igw
       - name: Gather information about a filtered list of VPC egress only internet gateways
         amazon.aws.ec2_vpc_egress_igw_info:
           filters:
             "tag:Name": "{{ _egress_igw.gateway_id }}"

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

    [Partial log]
    …
    "egress_only_internet_gateways": [
            {
                "attachments": [
                    {
                        "state": "attached",
                        "vpc_id": "vpc-12345678”
                    }
                ],
                "egress_only_internet_gateway_id": "eigw-0e91a0f2433018227",
                "tags": {}
            }
    ]

    What's next?

    In this final article of our series, we’ve demonstrated how the latest features in the amazon.aws 9.0.0 collection empower you to automate secure and scalable multi-VPC connectivity. By leveraging VPC peering, VPN connections, and egress-only internet gateways, we’ve shown how to build efficient and secure network architectures in AWS. This automation helps to reduce manual intervention, improve scalability, and ensure robust security for cloud environments.

    We hope this series has provided you with a deeper understanding of how these new modules and features can streamline the management of your AWS infrastructure. Stay tuned for future insights and tutorials on how to optimize and scale your AWS architecture with Ansible!

    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

    • How OpenShift Dev Spaces makes Ansible content testing easy

    • How Ansible Automation task scheduling improves productivity

    • How to deploy applications using Ansible Automation Platform

    Recent Posts

    • Red Hat UBI 8 builders have been promoted to the Paketo Buildpacks organization

    • Using eBPF in Red Hat products

    • How we made one data layer serve the UI, the mocks, and the E2E tests

    • Build trusted Python containers with Project Hummingbird and Calunga

    • Simplify distributed tracing: ObservabilityInstaller installation

    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