-
Notifications
You must be signed in to change notification settings - Fork 2
/
gce-cfme-ansible-create-webserver-instance.yml
74 lines (67 loc) · 2.9 KB
/
gce-cfme-ansible-create-webserver-instance.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
---
################################################################################################
# Create Instances in GCE #
# #
# By Robert J. Calva - Red Hat LATAM - 2017 #
# #
# Variable examples: #
# #
# zone: us-central1-a #
# instance_names: my-webtest-instance1,my-webtest-instance2,my-webtest-instance3 #
# machine_type: g1-small #
# image: centos-7-v20170523 #
# dns_zone: workshop.example.com #
# #
# #
# Enjoy! #
################################################################################################
- name: Create Instances in GCE
hosts: localhost
gather_facts: True
connection: local
tasks:
- name: Create an Instance based on image "{{image}}"
gce:
instance_names: "{{instance_names}}"
zone: "{{zone}}"
machine_type: "{{machine_type}}"
image: "{{image}}"
state: present
preemptible: true
# disk_size: "{{disk_size}}"
tags: http-server,https-server
register: gce
- name: Save host data within a Group
add_host:
hostname: "{{ item.public_ip }}"
groupname: gce_instances_temp
with_items: "{{ gce.instance_data }}"
- name: Wait for SSH to come up
wait_for: host={{ item.public_ip }} port=22 delay=10 timeout=60
with_items: "{{ gce.instance_data }}"
- name: setting fact
set_fact: host={{ item.public_ip }}
with_items: "{{ gce.instance_data }}"
- name: Record "{{instance_names}}" within "{{dns_zone}}"
gcdns_record:
zone: "{{dns_zone}}"
record: "{{instance_names}}.{{dns_zone}}"
type: A
overwrite: true
value: "{{ host }}"
- name: Configure Hosts post-creation
hosts: gce_instances_temp
gather_facts: True
remote_user: workshop
become: yes
become_method: sudo
tasks:
- name: install Apache
yum:
name: httpd
state: latest
- name: start Apache Service
service:
name: httpd
state: started
enabled: yes