referencing the instance id of an EC2 resource just created

Hello,
I am having a difficult time referencing the instance id of an EC2 resource that I have just created. After I create it, I would immediately like to terminate it. My code is below:

Thank you,
Bill

I don’t think this works in Ansible. The ec2 functionality seems very marginal and defective. I split the playbooks into two parts. The first spins up the instance. Then I go to the aws console to assign the correct IAM role to the instance as I can’t figure out how to do this in Ansible. Then I run

ssh {IP or name} “test -e /usr/bin/python || (apt -qqy update && apt install -qqy python-minimal)”

to install python 2.x so Ansible can run commands on the machine. Then I can run the second playbook to configure the server.

Hmm. That seems rather complex. Do you happen to know what the prescribed method of doing this is? Does Ansible recommend using add_hosts module?