Configure dynamic inventory for cloud providers
✓Works with OpenClaudeYou are an Ansible infrastructure automation specialist. The user wants to configure dynamic inventory for cloud providers so they can automatically discover and manage cloud resources without maintaining static host lists.
What to check first
- Run
ansible --versionto confirm Ansible is installed (2.9+) - Run
pip list | grep botoorpip list | grep azureto verify cloud provider SDKs are installed - Check if
~/.aws/credentialsor cloud provider credentials are configured locally - Verify the target cloud provider plugin is in
~/.ansible/plugins/inventory/or runansible-doc -l | grep inventory
Steps
- Install required cloud provider libraries:
pip install boto3 botocore(AWS),pip install azure-identity azure-mgmt-compute(Azure), orpip install google-auth(GCP) - Configure cloud credentials in environment variables or credential files (
~/.aws/credentials,~/.azure/credentials,~/.config/gcloud/) - Create an inventory configuration file with
.ymlor.yamlextension (e.g.,aws_ec2.yml) in your Ansible project root orinventory/directory - Define the plugin type and cloud-specific filters: set
plugin: aws_ec2,plugin: azure_rm, orplugin: gcp_compute - Add authentication parameters:
aws_profile,regions,auth_kind,project_iddepending on your cloud provider - Define host filtering and grouping rules using
keyed_groupsto organize hosts by tags, availability zones, or instance types - Add
composevariables to create custom host facts from cloud metadata (e.g., public IP, private IP, instance state) - Test inventory resolution with
ansible-inventory -i aws_ec2.yml --listto verify dynamic host discovery - Validate connectivity with
ansible all -i aws_ec2.yml -m pingto ensure Ansible can reach discovered hosts
Code
# aws_ec2.yml - AWS EC2 Dynamic Inventory
plugin: aws_ec2
# AWS Authentication
aws_profile: default
# Define regions to scan
regions:
- us-east-1
- us-west-2
# Filter EC2 instances by tag or state
filters:
tag:Environment: production
instance-state-name: running
# Group hosts by AWS metadata
keyed_groups:
# Create groups based on instance tag
- key: 'tags.Environment'
prefix: env
# Create groups by availability zone
- key: 'placement.availability_zone'
prefix: az
# Create groups by instance type
- key: 'instance_type'
prefix: type
# Compose custom variables from EC2 attributes
compose:
ansible_host: public_ip_address
private_ip: private_ip_address
instance_id: instance_id
instance_state: instance_state.name
# Set default SSH user per image
groups
Note: this example was truncated in the source. See the GitHub repo for the latest full version.
Common Pitfalls
- Treating this skill as a one-shot solution — most workflows need iteration and verification
- Skipping the verification steps — you don't know it worked until you measure
- Applying this skill without understanding the underlying problem — read the related docs first
When NOT to Use This Skill
- When a simpler manual approach would take less than 10 minutes
- On critical production systems without testing in staging first
- When you don't have permission or authorization to make these changes
How to Verify It Worked
- Run the verification steps documented above
- Compare the output against your expected baseline
- Check logs for any warnings or errors — silent failures are the worst kind
Production Considerations
- Test in staging before deploying to production
- Have a rollback plan — every change should be reversible
- Monitor the affected systems for at least 24 hours after the change
Related Ansible Skills
Other Claude Code skills in the same category — free to download.
Ansible Playbook
Write Ansible playbooks for server configuration
Ansible Role
Create reusable Ansible roles with defaults and handlers
Ansible Vault
Manage secrets with Ansible Vault encryption
Ansible Galaxy
Publish and consume roles from Ansible Galaxy
Ansible Testing
Test Ansible roles with Molecule and Testinfra
Ansible Idempotent Playbook
Write Ansible playbooks that can run repeatedly without causing changes when nothing needs to change
Ansible Vault for Secrets
Encrypt sensitive data in Ansible playbooks with Ansible Vault
Want a Ansible skill personalized to YOUR project?
This is a generic skill that works for everyone. Our AI can generate one tailored to your exact tech stack, naming conventions, folder structure, and coding patterns — with 3x more detail.