--- - connection: local gather_facts: false hosts: localhost tasks: - ec2: count: 3 image: ami-0cca6df87334a74bd instance_tags: type: webinar instance_type: t2.micro key_name: webinar wait: true user_data: "apt-get update && apt-get upgrade -y&& apt-get install -y python python-pip" name: "create machine" register: ec2 - name: run ssh-keyscan to add keys to known_hosts local_action: shell ssh-keyscan {{ item.public_ip }} >> ~/.ssh/known_hosts with_items: "{{ ec2.instances }}"