Yes you can use the add_host module to create an in-memory group. I am having weird issues with EC2 instances that I just posted about (
https://groups.google.com/forum/#!topic/ansible-project/jqRDPGqUof8) but I am able to run 2 commands on the newly provisioned hosts.
You need something like this using a registered ec2 variable from provisioning:
- name: Add all instance public IPs to in-memory group
add_host:
name: "{{ item.1.public_ip }}"
groups: ec2hosts
with_subelements:
- "{{ ec2.results }}"
- instances
and then you'd be able to use that group in another hosts section of your play:
- hosts: ec2hosts
user: ubuntu
gather_facts: false