bring ec2 example upto date
authorLorin Hochstein <lhochstein@netflix.com>
Sun, 12 Feb 2017 00:38:59 +0000 (16:38 -0800)
committerLorin Hochstein <lhochstein@netflix.com>
Sun, 12 Feb 2017 00:38:59 +0000 (16:38 -0800)
ch12/playbooks/ec2-example.yml

index 24996d0..73a64e9 100644 (file)
@@ -7,7 +7,7 @@
     count: 1
   tasks:
   - name: ec2 keypair
-    ec2_key: name=mykey key_material="{{ item }}" region={{ region }}
+    ec2_key: "name=mykey key_material={{ item }} region={{ region }}"
     with_file: ~/.ssh/id_rsa.pub
   - name: web security group
     ec2_group:
       rules_egress:
         - proto: all
           cidr_ip: 0.0.0.0/0
-  - name: Get the ubuntu trusty AMI
-    ec2_ami_search: distro=ubuntu release=trusty virt=hvm region={{ region }}
+  - name: Get the ubuntu xenial ebs ssd AMI
+    ec2_ami_find:
+      name: "ubuntu/images/hvm-ssd/ubuntu-xenial-16.04-amd64-server-*"
+      region: "{{ region }}"
+      sort: name
+      sort_order: descending
+      sort_end: 1
+      no_result_action: fail
     register: ubuntu_image
+  - set_fact: "ami={{ ubuntu_image.results[0].ami_id }}"
   - name: start the instances
     ec2:
       region: "{{ region }}"
-      image: "{{ ubuntu_image.ami }}"
+      image: "{{ ami }}"
       instance_type: "{{ instance_type }}"
       key_name: mykey
       group: [web, ssh, outbound]
     register: ec2
   - name: add the instance to web and production groups
     add_host: hostname={{ item.public_dns_name }} groups=web,production
-    with_items: ec2.tagged_instances
+    with_items: "{{ ec2.tagged_instances }}"
     when: item.public_dns_name is defined
   - 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
+    with_items: "{{  ec2.tagged_instances }}"
     when: item.public_dns_name is defined
 
 - name: configure webservers
   hosts: web:&production
-  sudo: True
+  become: True
+  gather_facts: False
+  vars:
+    ansible_python_interpreter: /usr/bin/python2.7
+  pre_tasks:
+    - name: install python
+      raw: apt-get install -y python2.7
   roles:
     - web