-
Notifications
You must be signed in to change notification settings - Fork 0
/
gen_playbook.py
57 lines (48 loc) · 1.44 KB
/
gen_playbook.py
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
import yaml
import json
#
# ---
# - hosts: lb
# remote_user: root
#
# vars:
# haproxy_backend_servers:
# - name: app1
# address: 127.0.0.1:8080
# - name: app2
# address: 127.0.0.2:8080
# roles:
# - ansible-role-haproxy
def main():
backend_servers = [{
"name": "app1",
"address": "127.0.0.1:8080"
},
{
"name": "app2",
"address": "127.0.0.2:8080"
},
{
"name": "app3",
"address": "127.0.0.3:8080"
}]
new_server = {"name": "foo1", "address": "100.1.1.1:8080"}
backend_servers.append(new_server)
lb_configuration = [
{
"remote_user": "root",
"hosts": "lb",
"vars": {
"haproxy_backend_servers":
backend_servers
},
"roles": [
"ansible-role-haproxy"
]
}
]
print(yaml.dump(lb_configuration))
# print "*" * 80
# print(json.dumps(lb_configuration, indent=4))
if __name__ == "__main__":
main()