Thanks for the deeper explanation, I get it now.

When you say "Most people only target localhost, instead of a group that 
contains multiple hosts." do you mean when I'm applying a role?  Because in 
the same playbook s the ec2 instance(s) creation i'm apply a role(s) to the 
newly created instances.  So the whole playbook is:
- hosts: ec2_test
  connection: local
  gather_facts: true
  tasks:
    - name: Launch Instance
      ec2:
        group_id: "{{ groupID }}"
        instance_type: 't2.micro'
        image: "{{ image }}"
        wait: true
        region: "{{ region }}"
        keypair: "{{ keypair }}"
        vpc_subnet_id: "{{ subnet }}"
        instance_tags:
          Name: "{{ inventory_hostname }}"
          ENV: "{{ tagEnv }}"
      register: ec2

    - name: Add hosts to group
      add_host: name="{{ hostvars[item]['ec2'].instances.0.private_ip }}" 
groups=dynamic
      with_items: "{{ play_hosts }}"

    - name: Wait for SSH
      wait_for:
        host: "{{ item.private_ip }}"
        port: 22
        delay: 10
        timeout: 320
        state: started
      with_items: "{{ ec2.instances }}"

    - name: Wait a little longer for centos
      pause: seconds=20


- hosts: dynamic
  gather_facts: yes
  sudo: yes
  roles:
    - hostname

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/51f8d182-7c0e-4666-b1a8-5071bbba36a2%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to