Search for EC2 Instances by Tag

I have a handful of existing EC2 instances with a specific tag that I would like to target and execute Ansible against. What is the best way to go about this?

I tried to use the ec2.py script for EC2 Dynamic Inventory, but ran into issues when trying to execute the script.

dchan $ chmod +x ec2.py
dchan $ ansible -i ec2.py us-east-1 -m ping
File “/ec2.py”, line 292
region ‘’’
^
IndentationError: expected an indented block

Is there something I’m doing wrong with the ec2.py script? I’m also unsure about how to incorporate the script into my playbook.
Are there any existing modules that I could utilize to solve my problem?

Thanks!

Sounds like a syntax error in ec2.py
Python uses whitespace indentation as part of the syntax. Did you open it in an editor an add or remove an white space?

Very strange, that’s right in the middle of a docstring. No reason for it to break like that.

What does the result of “/usr/bin/env python --version” say?

Regards,
-scott

Have you perhaps hand-edited (or someone has) ec2.py?

PEBKAC, it was a misconfiguration on my part. Script works like a charm!