add instance role
authorLorin Hochstein <lorin.hochstein@sendgrid.com>
Tue, 10 Feb 2015 00:14:05 +0000 (19:14 -0500)
committerLorin Hochstein <lorin.hochstein@sendgrid.com>
Tue, 10 Feb 2015 00:14:05 +0000 (19:14 -0500)
ch12/playbooks/instance-role.yml [new file with mode: 0644]

diff --git a/ch12/playbooks/instance-role.yml b/ch12/playbooks/instance-role.yml
new file mode 100644 (file)
index 0000000..0f8b4d3
--- /dev/null
@@ -0,0 +1,28 @@
+---
+- name: launch instance role
+  hosts: localhost
+  gather_facts: False
+  vars:
+    region: us-west-1
+    instance_type: t2.micro
+  tasks:
+  - name: Get the ubuntu trusty AMI
+    ec2_ami_search: distro=ubuntu release=trusty virt=hvm region={{ region }}
+    register: ubuntu_image
+  - name: start the instance
+    ec2:
+      region: "{{ region }}"
+      image: "{{ ubuntu_image.ami }}"
+      instance_type: "{{ instance_type }}"
+      key_name: mykey
+      group: [ssh, outbound]
+      instance_tags: { Name: instance-role, type: ansible }
+      exact_count: 1
+      count_tag: { type: ansible }
+      instance_profile_name: ansible
+      wait: yes
+    register: ec2
+  - name: wait for ssh server to be running
+    wait_for: host={{ item.public_dns_name }} port=22 search_regex=OpenSSH
+    with_items: ec2.tagged_instances
+    when: item.public_dns_name is defined