Building dynamic inventory with grouping on ansible using EC2 inventory plugin

Some background

My inventory setup

Current inventory setup

TO WAR (ノಠ益ಠ)ノ彡┻━┻

ansible-galaxy collection install
  • run only eu-west-3
  • configure the credentials on the file (DO NOT DO THIS IF THIS FILE IS GONNA BE EXPOSED SOMEWHERE, use env variables instead)
  • group by tags
  • filter by env staging
  • Get ip, dns name, tag Name tag env and private IP
inventory listing with enable_plugins set only for ec2

Testing time

ansible-inventory -i inventory/your-env --graph
ansible -m ping -i inventory/your-env host



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Adrian Angel Sanz Melchor

Just a spanish DevOps who likes sharing useful knowledge, working proudly @ MrMilú