--- # ============================================================================= # Production Environment - AWS EC2 Dynamic Inventory (EXAMPLE) # ============================================================================= # # This is an example configuration for AWS EC2 dynamic inventory. # Rename to aws_ec2.yml and configure with your AWS details. # # Requirements: # ansible-galaxy collection install amazon.aws # pip3 install boto3 botocore # # Authentication: # - AWS credentials via ~/.aws/credentials # - IAM role (recommended for EC2 control nodes) # - Environment variables (AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY) # # Usage: # ansible-inventory -i inventories/production/aws_ec2.yml --list # # ============================================================================= plugin: amazon.aws.aws_ec2 # AWS Regions to query regions: - us-east-1 - us-west-2 # - eu-west-1 # - ap-southeast-1 # Instance filters filters: tag:Environment: production instance-state-name: running # Use private IP for internal networks, public for external hostnames: - tag:Name - dns-name - private-ip-address # Compose variables compose: ansible_host: private_ip_address # For public access: # ansible_host: public_ip_address environment: production aws_region: placement.region aws_az: placement.availability_zone instance_type: instance_type vpc_id: vpc_id # Keyed groups keyed_groups: # Group by tag:Role - key: tags.Role prefix: role separator: "_" # Group by tag:Service - key: tags.Service prefix: service separator: "_" # Group by instance type - key: instance_type prefix: instance_type # Group by availability zone - key: placement.availability_zone prefix: az # Group by VPC - key: vpc_id prefix: vpc # Strict mode (fail if groups can't be created) strict: false # Cache settings cache: true cache_plugin: jsonfile cache_timeout: 3600 cache_connection: /tmp/ansible_aws_inventory_cache cache_prefix: aws_ec2 # Include/exclude patterns # include_filters: # - tag:Managed: ansible # exclude_filters: # - tag:Backup: only