EC2 Query Module

Is there an EC2 query module that allows you to look up various resources and associated metadata that can be registered as variables? I consistently seem to run across a problem using Ansible (I assume this is a lack of understanding or misuse of Ansible on my part) where I am doing a sequence of events like this:

  1. Look up an AMI with some specific tags
  2. Use said AMI to create ec2 instance(s)
  3. Add created instance(s) to dynamic hostgroup
  4. Provision instance(s) in dynamic hostgroup

I know how to achieve this, but my problem occurs if there is some sort of error in step #4. How do I re-assemble the state of steps 2 and 3, without running something like aws cli?

This is how I am doing an approximation of what I want, but I feel like I am doing something wrong. What I really want is to use registered variables, because those seem to be global to playbooks, where facts seem host specific.

Try this.

https://github.com/edx/configuration/blob/master/playbooks/library/ec2_lookup