Created
December 14, 2017 19:21
-
-
Save alexcheng1982/788034843a0944372bf106f17b14e29d to your computer and use it in GitHub Desktop.
Launch Windows instances
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
- hosts: localhost | |
vars_files: | |
- secret.yml | |
gather_facts: no | |
tasks: | |
- name: create ec2 windows server security group | |
ec2_group: | |
name: "{{ aws.windows_security_group }}" | |
description: Windows server | |
region: "{{ aws.region }}" | |
rules: | |
- proto: tcp | |
from_port: 3389 | |
to_port: 3389 | |
cidr_ip: 0.0.0.0/0 | |
- proto: tcp | |
from_port: 5986 | |
to_port: 5986 | |
cidr_ip: 0.0.0.0/0 | |
rules_egress: | |
- proto: -1 | |
cidr_ip: 0.0.0.0/0 | |
register: sg_out | |
- name: launch windows ec2 instance | |
ec2: | |
region: "{{ aws.region }}" | |
key_name: "{{ aws.key }}" | |
instance_type: "{{ aws.instance_type }}" | |
spot_price: "{{ aws.windows_spot_price }}" | |
image: "{{ aws.windows_image }}" | |
group_id: "{{ sg_out.group_id }}" | |
wait: yes | |
instance_tags: | |
Name: My windows server | |
instance_uid: my_windows_server | |
build_num: "{{ build_num }}" | |
role: dev | |
exact_count: 1 | |
count_tag: | |
instance_uid: my_windows_server | |
user_data: "{{ lookup('template', 'templates/userdata.txt.j2') }}" | |
register: ec2 | |
- name: wait for windows server to answer on all hosts | |
wait_for: | |
port: 5986 | |
host: "{{ item.public_ip }}" | |
timeout: 300 | |
with_items: "{{ ec2.tagged_instances }}" | |
- name: add windows hosts to groups | |
add_host: | |
name: "win-{{ item.id }}" | |
ansible_ssh_host: "{{ item.public_ip }}" | |
groups: win, dev | |
changed_when: false | |
with_items: "{{ ec2.tagged_instances }}" | |
- name: add cname | |
route53: | |
state: present | |
zone: mycompany.com | |
record: "app-{{ build_num }}.mycompany.com" | |
type: CNAME | |
value: "{{ item.public_dns_name }}" | |
ttl: 30 | |
overwrite: yes | |
with_items: "{{ ec2.tagged_instances }}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment