I’m trying to start a marketplace instance and secure it all in the same playbook. That requires copying some files and running a provisioning script. I’d prefer to keep all that in a single playbook, to reduce chances of error and keep it semi-atomic. It doesn’t seem to be possible even with the dynamic inventory capability, since the state of the system is determined at the beginning of the playbook, and there is no way I can see to otherwise indicate the target host for the copy and script modules.
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