From 7df541e831c7ea7beaad00e318e8a5771e0053bd Mon Sep 17 00:00:00 2001 From: Lorin Hochstein Date: Sat, 11 Feb 2017 16:38:59 -0800 Subject: [PATCH] bring ec2 example upto date --- ch12/playbooks/ec2-example.yml | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/ch12/playbooks/ec2-example.yml b/ch12/playbooks/ec2-example.yml index 24996d0..73a64e9 100644 --- a/ch12/playbooks/ec2-example.yml +++ b/ch12/playbooks/ec2-example.yml @@ -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: @@ -41,13 +41,20 @@ 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] @@ -58,15 +65,21 @@ 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 -- 2.44.0