-
Notifications
You must be signed in to change notification settings - Fork 0
/
ansblock.py
104 lines (80 loc) · 2.61 KB
/
ansblock.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
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
#!/usr/bin/python2
import cgi
import commands
print "Content-Type: text/html"
print
user=cgi.FormContent()['user'][0]
paswd=cgi.FormContent()['paswd'][0]
ip=cgi.FormContent()['ip'][0]
vg=cgi.FormContent()['vg'][0]
clientpass=cgi.FormContent()['clientpass'][0]
clientip=cgi.FormContent()['clientip'][0]
size=cgi.FormContent()['size'][0]
print user
write="""[storageserver]
{0} ansible_ssh_user=root ansible_ssh_pass={1}
[webserver]
192.168.43.150 ansible_ssh_user=root ansible_ssh_pass=blackhat
[clientserver]
{2} ansible_ssh_user=root ansible_ssh_pass={3}
""".format(ip,paswd,clientip,clientpass)
print write
print commands.getstatusoutput("sudo touch /webcontent/Ansible/hosts")
print commands.getstatusoutput("sudo chown apache /webcontent/Ansible/hosts")
f2=open("/webcontent/Ansible/hosts",'w')
f2.write(write)
f2.close()
#print user
#print paswd
write1="""---
- hosts: storageserver
tasks:
- package:
name: "scsi-target-utils.x86_64"
state: present
- file:
state: directory
path: "/gbs"
- fetch:
src: "/etc/tgt/targets.conf"
dest: "/gbs/"
flat: yes
- lvol:
vg: "{0}"
lv: "{1}"
size: "{2}"
- hosts: webserver
tasks:
- file:
path: "/gbs/targets.conf"
owner: "apache"
- blockinfile:
path: "/gbs/targets.conf"
block: |
<target {1}>
backing-store /dev/{0}/{1}
</target>
- hosts: storageserver
tasks:
- copy:
src: "/gbs/targets.conf"
dest: "/etc/tgt/targets.conf"
- service:
name: "tgtd"
state: restarted
- hosts: clientserver
tasks:
- open_iscsi:
show_nodes: yes
discover: yes
portal: {3}
login: yes
target: {1}
""".format(vg,user,size,ip)
commands.getstatusoutput("sudo touch /webcontent/Ansible/part1.yml")
commands.getstatusoutput("sudo chown apache /webcontent/Ansible/part1.yml")
f1=open("/webcontent/Ansible/part1.yml",'w')
f1.write(write1)
f1.close()
print commands.getstatusoutput("sudo ansible-playbook ../Ansible/part1.yml -i ../Ansible/hosts")
print "Allocated"