- name: check/create instance hosts: myhostname user: root gather_facts: False vars: - instance_type: m1.xlarge - image: emi-3F1C4010 - keypair: admin - security_group: webserver - public_ip: 192.168.1.2 tasks: # check to see if it is already listening on sshd on the ip we want for it - name: check it out local_action: shell nc -d -z -w 5 ${public_ip} 22 >>/dev/null register: host_is_up ignore_errors: true # if it is not up then we bring it up - name: spin it up local_action: ec2 keypair=${keypair} image=${image} type=${instance_type} wait=true group=${security_group} register: inst_res only_if: "'${host_is_up.rc}' != '0'" # associate an ip - name: assign it a special ip local_action: shell euca-associate-address -i ${inst_res.instances[0].id} ${public_ip} only_if: "'${host_is_up.rc}' != '0'" # wait for it to come up and function - name: wait for the reassignation local_action: wait_for host=${public_ip} port=22 delay=20 timeout=300 only_if: "'${host_is_up.rc}' != '0'" # this way you can always run this second play - just to # keep your box in shape - the first one won't get run once the # host is up - name: provision instance hosts: myhostname user: root gather_facts: True tasks: - name: install pkgs for jenkins action: yum state=installed pkg=$item with_items: - vim - java-1.7.0-openjdk - subversion - bzr - git tags: - packages