forked from Azure-Samples/ansible-playbooks
-
Notifications
You must be signed in to change notification settings - Fork 0
/
appgateway_create.yml
146 lines (135 loc) · 4.49 KB
/
appgateway_create.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
# Description
# ===========
# This playbook creates an Application Gateway. The azure_rm_appgw module is available in v2.7. If you are using Ansible 2.5 or 2.6
# You need to run "ansible-galaxy install azure.azure_preview_modules" to install the role to get lastest Ansible modules.
# 1. create resource group
# 1. create virtual network
# 1. create subnet
# 1. create application gateway
---
- hosts: localhost
tasks:
- name: Prepare random postfix
set_fact:
rpfx: "{{ 1000 | random }}"
run_once: yes
- hosts: localhost
# If you are using Ansible v2.7. Remove below two lines since azure_rm_appgw module is available in v2.7.
roles:
- azure.azure_preview_modules
vars:
resource_group: "{{ resource_group_name }}"
location: eastus
vnet_name: ansiblevnetname
subnet_name: ansiblesubnetname
appgw_name: appgw{{ rpfx }}
azure_subscription_id: "{{ lookup('env','AZURE_SUBSCRIPTION_ID') }}"
tasks:
- name: Create a resource group
azure_rm_resourcegroup:
name: "{{ resource_group }}"
location: "{{ location }}"
- name: Create a container with httpd image
azure_rm_containerinstance:
resource_group: "{{ resource_group }}"
name: "aci{{ resource_group | hash('md5') | truncate(7, True, '') }}"
os_type: linux
ip_address: public
location: eastus
ports:
- 80
containers:
- name: mycontainer1
image: httpd
memory: 1.5
ports:
- 80
register: ci_output_a
- name: Create another container with httpd image
azure_rm_containerinstance:
resource_group: "{{ resource_group }}"
name: "aci{{ resource_group | hash('md5') | truncate(7, True, '') }}b"
os_type: linux
ip_address: public
location: eastus
ports:
- 80
containers:
- name: mycontainer1
image: httpd
memory: 1.5
ports:
- 80
register: ci_output_b
- name: Dump first container instance output
debug:
var: ci_output_a
- name: Dump second container instance output
debug:
var: ci_output_b
- name: Create a virtual network
azure_rm_virtualnetwork:
name: "{{ vnet_name }}"
resource_group: "{{ resource_group }}"
address_prefixes_cidr:
- 10.1.0.0/16
- 172.100.0.0/16
dns_servers:
- 127.0.0.1
- 127.0.0.2
- name: Create a subnet
azure_rm_subnet:
name: "{{ subnet_name }}"
virtual_network_name: "{{ vnet_name }}"
resource_group: "{{ resource_group }}"
address_prefix_cidr: 10.1.0.0/24
register: subnet_output
- name: Create a public IP address
azure_rm_publicipaddress:
resource_group: "{{ resource_group }}"
allocation_method: Dynamic
name: appgwpublicip
domain_name_label: "{{ resource_group }}"
register: pip_output
- name: Dump Public IP output
debug:
var: pip_output
- name: Create instance of Application Gateway
azure_rm_appgw:
resource_group: "{{ resource_group }}"
name: "{{ appgw_name }}"
sku:
name: standard_small
tier: standard
capacity: 2
gateway_ip_configurations:
- subnet:
id: "{{ subnet_output.state.id }}"
name: app_gateway_ip_config
frontend_ip_configurations:
- public_ip_address: appgwpublicip
name: sample_gateway_frontend_ip_config
frontend_ports:
- port: 80
name: ag_frontend_port
backend_address_pools:
- backend_addresses:
- ip_address: "{{ ci_output_a.ip_address }}"
- ip_address: "{{ ci_output_b.ip_address }}"
name: test_backend_address_pool
backend_http_settings_collection:
- port: 80
protocol: http
cookie_based_affinity: enabled
name: sample_appgateway_http_settings
http_listeners:
- frontend_ip_configuration: sample_gateway_frontend_ip_config
frontend_port: ag_frontend_port
name: sample_http_listener
request_routing_rules:
- rule_type: Basic
backend_address_pool: test_backend_address_pool
backend_http_settings: sample_appgateway_http_settings
http_listener: sample_http_listener
name: rule1
register: output