forked from llima3000/ansibledevops
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreateDataScript.yml
66 lines (64 loc) · 2.36 KB
/
createDataScript.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
---
#ansible-playbook createDataSript.yml
- hosts: localhost
connection: local
vars:
controller: 10.91.55.10
username: admin
password: Avi123$%
api_version: 17.2.7
tenant: admin
name: CV1-hosts
pool_name1: pool1
pool_name2: pool2
pool_name3: pool3
string_group_name: CV1-hosts
roles:
- role: avinetworks.avisdk
tasks:
- name: "Create Data Script - {{ name }}"
avi_vsdatascriptset:
username: "{{ username }}"
password: "{{ password }}"
controller: "{{ controller }}"
api_version: "{{ api_version }}"
name: "{{ name }}"
tenant_ref: "/api/tenant/?name={{ tenant }}"
datascript:
- evt: VS_DATASCRIPT_EVT_HTTP_REQ
script: |-
-- HTTP_REQUEST
default_pool = "default_pool"
host = avi.http.get_header("Host")
-- if host header exists
if host then
-- lookup pool name using host header value from pools_stringgroup
-- assuming host header name is used as key in stringgroup pools_stringgroup
-- pools_stringgroup entries will look like www.example.com:www.example.com_pool, where host header value is key and pool name is value
-- pools and stringgroup has to be attached to datascript
pool, match = avi.stringgroup.contains("CV1-hosts", host)
-- if pool found i.e. match == true
avi.vs.log(match)
if match then
servers_up, servers_total = avi.pool.get_servers(pool)
-- verify that pool functional and has servers up
if servers_up >= 1 then
avi.pool.select(pool)
avi.vs.log("SELECTED_POOL:" .. pool)
-- if no, use default pool
else
avi.pool.select(default_pool)
avi.vs.log("SELECTED_POOL:" .. default_pool)
end
-- if no, use default pool
else
avi.pool.select(default_pool)
avi.vs.log("SELECTED_POOL:" .. default_pool)
end
end
pool_refs:
- "/api/pool/?name={{ pool_name1 }}"
- "/api/pool/?name={{ pool_name2 }}"
- "/api/pool/?name={{ pool_name3 }}"
string_group_refs:
- "/api/stringgroup/?name={{ string_group_name }}"